ProgrammingHardProduct-company placement · C++

Which line fails to compile?

Which line fails to compile?
struct P { const int id; };
int main() {
    P a{1}, b{2};
    P c = a;    // L1
    a = b;      // L2
}
  1. A. L1 only
  2. B. L2 only
  3. C. Both
  4. D. Neither

Correct answer: B. L2 only

A const data member can be copied into a new object, so the copy constructor is fine, but it cannot be reassigned, so the implicit copy assignment operator is defined as deleted.

More OOP with C++ and Java questions

Exams that ask this topic