I made class time ,
and declared in main :
time a;
time b=a;
is this the same as :
time b(a);
???
I also made function :
time f(time t)
{
return t;
}
and used it in main after declaring a :
time b=f(a);
I printed messages when copy constructor called , the Result was only 2 calls to copy constructor ,one copying a to t, the other is copying t to return , here is my question there was no call to copy constructor to copy the value returned from function to b ?
thanks in advance !
The question in your header and the question at the bottom of your post are different. For the one in your header:
Not exactly. First the expression on the right side is converted to the type on the left side, and then the copy constructor is called. This requires an implicit conversion. If one is not possible, the initialization will not compile. If the expression on the right side is already the right type, then the first step is not necessary.
For your other question, this is return value optimization.