将引用 return 值分配给非引用变量
Assign a reference return value to a non-reference variable
class A { ... };
A& getA();
A anA = getA();
第 3 行到底发生了什么?
是否调用了 A 的复制构造函数,从而创建了一个独立于函数返回(通过引用)的对象?
Is the copy constructor of A called, thus creating an object independent from the one returned (by reference) by the function?
是的。复制构造函数将对源对象的引用作为它的参数,并且副本独立于原始对象,假设复制构造函数执行深层复制。
class A { ... };
A& getA();
A anA = getA();
第 3 行到底发生了什么?
是否调用了 A 的复制构造函数,从而创建了一个独立于函数返回(通过引用)的对象?
Is the copy constructor of A called, thus creating an object independent from the one returned (by reference) by the function?
是的。复制构造函数将对源对象的引用作为它的参数,并且副本独立于原始对象,假设复制构造函数执行深层复制。