M
MathWizard
Hi,
I have a question about returning an object in a function and calling a
copy constructor. As far as I understand, in the following code the copy
constructor may or may not be called, depending on the compiler:
A what()
{
A my_A;
// do something with A.
return A;
}
Suppose I have also a class B and a constructor for A from B:
A::A(const B& b);
The question is now about the following code:
A what()
{
B my_B;
// do something with B.
return B;
}
As far as I can see, the constructor 'A::A(const B& b)' must be called
in order to return an object A. But is it possible that after that
constructor some (stupid) compiler decides that the copy constructor for
A must be called also? Maybe some compiler might think that the copy
constructor must be called always if an object must be returned...
Thansk for any answers,
Jeroen
I have a question about returning an object in a function and calling a
copy constructor. As far as I understand, in the following code the copy
constructor may or may not be called, depending on the compiler:
A what()
{
A my_A;
// do something with A.
return A;
}
Suppose I have also a class B and a constructor for A from B:
A::A(const B& b);
The question is now about the following code:
A what()
{
B my_B;
// do something with B.
return B;
}
As far as I can see, the constructor 'A::A(const B& b)' must be called
in order to return an object A. But is it possible that after that
constructor some (stupid) compiler decides that the copy constructor for
A must be called also? Maybe some compiler might think that the copy
constructor must be called always if an object must be returned...
Thansk for any answers,
Jeroen