Assign a reference return value to a variable without a reference

class A { ... };
A& getA();
A anA = getA();

What exactly happens on line 3?

Is the creator of copy A called, thus creating an object independent of the function returned (by reference)?

+4
source share
1 answer

Is the creator of copy A called, thus creating an object independent of the function returned (by reference)?

Yes. The copy constructor refers to the source object as its parameter, and the copy does not depend on the source object if the copy constructor performs a deep copy.

+8
source

All Articles