class A { ... };
A& getA();
A anA = getA();
What happens exactly on line 3 ?
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();
What happens exactly on line 3 ?
Is the copy constructor of A called, thus creating an object independent from the one returned (by reference) by the function?
Copyright © 2021 Jogjafile Inc.
Yes. The copy constructor takes a reference to the source object as it's parameter and a copy is independent of the original object assuming the copy constructor does a deep copy.