10 questions
4
votes
0
answers
212
views
Need of explicit copy constructor if virtual destructor defined
After update, my Visual Studio compiler started producing "warning C5267: definition of implicit assignment operator for 'Value' is deprecated because it has a user-provided destructor" with ...
1
vote
0
answers
70
views
Why does a nested class with an implicitly-defined default constructor not satisfy std::default_initializable? [duplicate]
In the following code, only Bar3 fails. What is the reason behind this static assertion failure?
#include <concepts>
struct Bar1 { Bar1() = default; bool val = false; };
static_assert(std::...
0
votes
0
answers
1k
views
error: use of deleted function operator=(&&) with std::optional
I got myself an error sprouting from std::optional. Now when trying to reconstruct it, there seems to be something going on with defaulted ctors that I don't yet understand. Consider the following ...
8
votes
1
answer
292
views
Prefer one type convert into another through implicit constructor or implicit conversion operator?
Assume we have procedure void f(X2);. Further assume we have types X1 and X2 that do not share an inheritance hierarchy.
We want to call it like this: f(X1{}) and have X1 implicitly convert into X2. ...
3
votes
1
answer
406
views
Default and Parameterized constructors and object declaration
I've written this code:
#include<iostream>
using namespace std;
class Student {
public:
string name;
int age;
Student() {
cout<<"Default constructor&...
0
votes
0
answers
273
views
C# generics equivalent of C++ template specialization/implicit constror
Is there any way to emulate C++ template specialization using C# generics and/or rtti?
Consider following functions, implementation details do not matter:
public void DrawShape(Shape sh, Brush brush1, ...
2
votes
3
answers
1k
views
Is implicit construction of `const std::string` from `const char *` efficient?
Like many people I'm in the habit of writing new string functions as functions of const std::string &. The advantages are efficiency (you can pass existing std::string objects without incurring ...
0
votes
1
answer
337
views
How can I detect whether a class has an implicit constructor AND primitive members in c++?
I want to detect during compile time (static assertion) whether a class meets both the following conditions:
Has an implicit default constructor (i.e., no user-defined default constructor).
Has at ...
5
votes
1
answer
402
views
Why is forwarding reference constructor called instead of copy constructor?
Given the following code
#include <iostream>
using namespace std;
template <typename Type>
struct Something {
Something() {
cout << "Something()" << endl;
}
...
4
votes
2
answers
5k
views
Move object without a move constructor
One more time about this, but the related questions do not answer my question.
The standard is pretty clear:
12.8 Copying and moving class objects,
§9
If the definition of a class X does not ...