I have a question about the following code:
let's say I have a class P that has a copy constructor and a regular constructor the receives one string value.
I have the following code:
P doSomething(){
P p("myValue");
return p;
}
int main(){
P m=doSomething();
return 1;
}
- why isn't copy constructor invoked at the
return p
of thedoSomething()
function? - the call
P m=doSomething()
- does it suppose to call the copy constructor or the operator=? in case it's operator =, what is the difference of this code and the following:
P new_val=("newVal"); p m=new_val;
(i know here the call is for copy constructor)
Thanks, Mary