ProgrammingVery hardProduct-company placement · C++

Which line fails to compile?

Which line fails to compile?
struct A { A(int) { } };
struct B { B(A) { } };
void f(B) { }
int main() {
    f(A(1));   // L1
    f(1);      // L2
}
  1. A. L2 only
  2. B. L1 only
  3. C. Both
  4. D. Neither

Correct answer: A. L2 only

An implicit conversion sequence may contain at most ONE user-defined conversion. A → B (via B(A)) is one; int → A → B would need two, so f(1) is rejected.

More OOP with C++ and Java questions

Exams that ask this topic