A question about 'Return Value'
I have the following code just for fun
Code:
class Base{
public:
Base(){cout<<"Constructor"<<endl;}
Base(const Base &obj){cout<<"Copy Constructor"<<endl;}
Base & operator=(const Base& obj){
cout<<"Operator="<<endl;
return *this;
}
};
Base foo(){
Base x;
return x;
}
void main(){
Base tmp = foo();
}
=================
Why the outputs are only
Constructor
Copy Constructor
But I think the outputs should be:
Constructor
Copy Constructor // from return x
Copy Constructor // from Base tmp = foo();