What this C++ copy-constructor question tests
This is a medium-difficulty C++ language-knowledge question that probes your understanding of copy semantics, object lifecycle, and compiler-generated special member functions. It rewards careful reading of code flow and knowledge of when and how the copy constructor is invoked.
To answer it, you need to trace through object construction and assignment, predict which constructors or operators are called at each step, and understand the implications for the program's output. The question is titled suggestively—the answer hinges on whether a copy constructor is actually being used, when you might expect one to be, or whether the compiler optimises it away entirely.
- Copy constructor vs. copy assignment operator
- Return value optimisation (RVO) and elision
- Implicit vs. explicit construction
- Compiler-generated vs. user-defined special members