Sorry i am struggling to grasp copy constructors,i would like to know why does the copy constructor get invoked only when i call a object in a function by value "op.return_Value(op)<
class operation{
public:
int add(int x,int y){
*total=x+y;
return (*total);
}
operation(){
cout<<"This is the constructor"<<endl;
total=new int;
}
operation(const operation &op){
cout<<"This is the copy of the start"<<endl;
total=new int;
*total=*op.total;
}
~operation(){
cout<<"This is the end";
delete total;
}
int *total;
int return_Value(operation op){
return *total;
}
};
class child_operation:operation{
public:
int sub(int x,int y){
*total=x-y;
return(*total);
}
};
int main()
{
operation op;
child_operation op1;
cout<<op.add(5,6)<<endl<<op1.sub(6,5)<<endl;
cout<<op.return_Value(op)<<endl;
}
Basically in which ways is a copy constructor invoked?