ProgrammingHardProduct-company placement · C++

Which lines fail to compile?

Which lines fail to compile?
struct U { U() { } U(const U&) = delete; };
void take(U u) { }
int main() {
    U a;           // L1
    U b = a;       // L2
    U& r = a;      // L3
    take(a);       // L4
}
  1. A. L2 only
  2. B. L2 and L4
  3. C. L4 only
  4. D. L2, L3 and L4

Correct answer: B. L2 and L4

With the copy constructor deleted, copying an lvalue is ill-formed: both copy-initialising b and passing a by value need it. Binding a reference copies nothing.

More OOP with C++ and Java questions

Exams that ask this topic