class demo{
private:
int x;
public:
demo(int t):x(t) {cout<<"constructor"<<endl;}
demo(const demo& t):x(t.x) {cout<<"copy constructor"<<endl;}
demo& operator=(const int& t){
x=t;
cout<<"assignment"<<endl;
}
demo& operator=(const demo& t){
x=t.x;
cout<<"copy assignment"<<endl;
}
~demo()
{
cout<<"deconstruction"<<endl;
}
};
int main()
{
demo x=2; // if the deconstruct function is called here, then it should be three "deconstruction"
demo y(2);
y=3;
}
the code above output two "deconstruction", I suppose it should be three. because "demo x = 2", in my opinion is just like "demo x = demo(2)", so when demo(2) is deconstructed, it should be a "deconstruction" message ouputed. then at the end of the program, x and y is deconstructed. so there should be 3 "deconstruction" output.