ProgrammingVery hardProduct-company placement · C++

Which lines fail to compile?

Which lines fail to compile?
void f(int) { cout << "I"; }
void f(double) = delete;
int main() {
    f(5);      // L1
    f('a');    // L2
    f(2.5);    // L3
    f(2.5f);   // L4
}
  1. A. L3 only
  2. B. L2, L3 and L4
  3. C. L4 only
  4. D. L3 and L4

Correct answer: D. L3 and L4

Deleted functions still take part in overload resolution; choosing one is an error. char → int is a promotion (L2 picks f(int)), but float → double is also a promotion, which beats float → int, so f(2.5f) selects the deleted overload.

More OOP with C++ and Java questions

Exams that ask this topic