Possible Duplicate:
Copy Constructor is not invoked
# include <iostream>
using namespace std;
class Abc
{
public:
int a;
Abc()
{
cout<<"def cstr\n";
a=10;
}
Abc(const Abc &source)
{
a=source.a;
cout<<"copy constructor is called"<<endl;
}
};
int main()
{
Abc kk = Abc();
cout<<kk.a<<endl;
return 0;
}
In the above program my output is :
def cstr
10
Here I expected that copy constructor would be called after the default contructor which is not happening.
Please tell me whats going on here. Is it because Abc() is creating a temp object ??
Please correct me if I am wrong.
thanks !!!