V
vairavans
Hi Everyone,
I have the following code,
class B
{
};
class A
{
public: A()
{
}
A(B& ref_obj)
{
printf("conversion\n");
}
~A()
{
}
A operator=(const B& ref)
{
printf("operator\n");
return A();
}
};
int main()
{
A obj;
B obj1;
obj = obj1; // invokes the operator=
A obj2 = obj1 // invokes the constructor conversion
obj2 = obj1 // invokes the constructor conversion, when
the operator= function is commented out
return(0);
}
What does the standard say about this? invoking a constructor when the
object on lvalue is already created...
I have the following code,
class B
{
};
class A
{
public: A()
{
}
A(B& ref_obj)
{
printf("conversion\n");
}
~A()
{
}
A operator=(const B& ref)
{
printf("operator\n");
return A();
}
};
int main()
{
A obj;
B obj1;
obj = obj1; // invokes the operator=
A obj2 = obj1 // invokes the constructor conversion
obj2 = obj1 // invokes the constructor conversion, when
the operator= function is commented out
return(0);
}
What does the standard say about this? invoking a constructor when the
object on lvalue is already created...