Given a class X
class X {
public: X(int);
X(const X&); //. . .
};
Is this line
X x1(1);
the same thing as
X x2 = 2;
That is, does the initialization of x2 result in a call the copy constructor
and nothing else, period. Is that what the standard says should happen?
Or, is the code generated for x2(2) more properly equivalent, according to
the standard, to something like
X tmp(2);
X x2(tmp);
tmp.~X();
with the difference being that the compiler may simply optimize away the
creation of the temporary, so the initialization x2 results in just a
single call to the copy constructor.
thanks
class X {
public: X(int);
X(const X&); //. . .
};
Is this line
X x1(1);
the same thing as
X x2 = 2;
That is, does the initialization of x2 result in a call the copy constructor
and nothing else, period. Is that what the standard says should happen?
Or, is the code generated for x2(2) more properly equivalent, according to
the standard, to something like
X tmp(2);
X x2(tmp);
tmp.~X();
with the difference being that the compiler may simply optimize away the
creation of the temporary, so the initialization x2 results in just a
single call to the copy constructor.
thanks
Comment