In this code :
class iop {
public:
iop(int y) {
printf("OK\n");
}
iop() {
printf("NO\n");
}
};
int main()
{
line 1- iop o;
line 2- o = 8;
line 3- return 0;
}
My conclusion of the way this C++ code work with is:
Create an object of
iop
class (o
) using the default parameterless constructor.Create an rvalue object of
iop
class using the constructor with parameter (int) and using the overloaded operator (operator = (iop&&)) to assign it to the object (o
) then call the destructor of that rvalue.Call the destructor of the object (
o
).
Is my conclusion correct?
Edit This code also compiled
class iop {
public:
iop(int y) {
printf("OK\n");
}
iop() {
printf("NO\n");
}
};
int main()
{
iop o(5);
o = 8;
return 0;
}
output :
OK
OK
That is mean two object are created (o) and one is temporary and the operator= assigen (o) with the temporary object that its constractor argument is 8