Hi,
I studied that copy constructor will get called when a function returns object.But in my case it dint.I have attached the sample code below.
Thanks in Advance
class base
{
public:
base()
{
cout<<"constructor"<<endl;
}
base( const base &b)
{
cout<<"copy constructor"<<endl;
}
};
base f1()
{
base b;
return b;
}
base f1(base c)
{
base b;
return b;
}
int main()
{
base a;
base b = a;
base c(b);
b=a;
c =f1(); //expecting copy constructor to get called,but it dint
a = f1(b);
return 0;
}
Output is:
constructor
copy constructor
copy constructor
constructor
copy constructor
constructor