Questions tagged [implicit-constructor]
9 questions
8
votes
1 answer
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. We have two options of achieving this:
struct X2…

Post Self
- 1,471
- 2
- 14
- 34
5
votes
1 answer
Why is forwarding reference constructor called instead of copy constructor?
Given the following code
#include
using namespace std;
template
struct Something {
Something() {
cout << "Something()" << endl;
}
template
Something(SomethingType&&) {
…

Curious
- 20,870
- 8
- 61
- 146
4
votes
2 answers
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 explicitly declare a move constructor, one will be…

Kiril Kirov
- 37,467
- 22
- 115
- 187
3
votes
1 answer
Default and Parameterized constructors and object declaration
I've written this code:
#include
using namespace std;
class Student {
public:
string name;
int age;
Student() {
cout<<"Default constructor"<

RAHUL JANGRA
- 67
- 3
2
votes
3 answers
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 overhead for copying/moving) and…

jez
- 14,867
- 5
- 37
- 64
1
vote
0 answers
Why does a nested class with an implicitly-defined default constructor not satisfy std::default_initializable?
In the following code, only Bar3 fails. What is the reason behind this static assertion failure?
#include
struct Bar1 { Bar1() = default; bool val = false; };
static_assert(std::default_initializable);
struct Bar2 { Bar2() {} bool…

MarkB
- 672
- 2
- 9
0
votes
0 answers
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 abstracted example:
I'm assigning a config struct…

glades
- 3,778
- 1
- 12
- 34
0
votes
0 answers
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, ...) { ... }
public void DrawShape(Shape sh,…

noisy cat
- 2,865
- 5
- 33
- 51
0
votes
1 answer
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 least one data member which is a pod (i.e., a…

Eran Bentov
- 3
- 1