Consider this code
class A{
int i;
public:
A(){
cout<<"default constructor\n";
}
~A(){
cout<<"default destrutor\n";
}
/* uncommenting this causes error
A(A& obj){
i=obj.i;
cout<<"copy constructor\n";
}
*/
};
A fun(){
A b;
cout<<" address of b = "<<&b<<endl;
return b;
}
int main(){
A a=fun();
cout<<" address of a = "<<&a<<endl;
return 0;
}
Doubts:
1. Why only 1 destructor is getting called.
2. Why address of a and b are same.
3. If I use copy constructor here, then the first line of main() is giving error
4. Constructor is getting called for object b which it should be, but destructor is getting called for object a.
5)Why am i not allowed to create a copy-constructor in this class?