using namespace std;
Object returnObject(){
Object o;
return o; //place A
}
int main() {
Object CopiedO=returnObject();
return 0; //Place B
}
the object definition is:
Object::Object() {
cout<<"Object::Object"<<endl;
}
Object::~Object() {
cout<<"Object::~Object"<<endl;
}
Object::Object(const Object& object) {
cout<<"Object::CopyObject"<<endl;
}
the result is:
/*Object::Object
Object::~Object*/
As I understand, both o and CopiedO in will be deconstructed, but why only once Object::~Object be printed?
I think there is no inline and the copied o is copy of o .but it can't print Object::CopyObject