ProgrammingHardMicrosoft/Google SDE MCQ · GATE CS

What is printed?

What is printed?
struct T {
    T() { }
    T(const T&) { cout << "C"; }
};
struct W { T t; };
int main() {
    W a;
    W b = std::move(a);
}
  1. A. C
  2. B. Nothing
  3. C. M
  4. D. Compile error: W has no move constructor

Correct answer: A. C

W gets an implicit move constructor that moves t. T has a user-declared copy constructor, so it has no implicit move constructor, and the rvalue binds to T(const T&): C.

More OOP with C++ and Java questions

Exams that ask this topic