the obj should have been destroyed at the end of function call 'f', the object returned should have been a new object. I should have got the "Destroying" message twice.
#include <iostream>
using namespace std;
class c{
int i;
public:
~c(){cout<<"Destroying"<<endl;}
c(){cout<<"Constructing"<<endl;}
c(const c &a){cout<<"Copy Constructing"<<endl;}
int get_i(){cout<<i<<endl;return i;}
void set_i(int i){this->i=i;}
};
c f(){
c obj;
obj.set_i(1);
return obj;
}
int main() {
f().get_i();
return 0;
}