1

Why doesen't it use any of my defined constructors during creation of newA? I thought that non-explicit calls of copy and conversion constructors look similar, but somehow I was wrong, I guess.

struct B;

struct A
{
    A(){ cout<<"Default\n"<<flush; }
    A(const B&){ cout<<"Convert\n"<<flush; }
    A(const B&&){ cout<<"Convert rvalue\n"<<flush; }
    A(const A&&){ cout<<"Copy rvalue\n"<<flush; }
    A(const A&){ cout<<"Copy\n"<<flush; }
};

struct B
{   
    operator A(){ A k; return k; }
};

int main()
{

B newB;

//Prints nothing
A newA(B());

//Prints "Convert rvalue"
A newerA = A(B());

return 0;
}
P. Talaga
  • 11
  • 1

0 Answers0