Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What happens when an overloaded function is called in C++ but matches none of the overloaded functions exactly?

  1. A runtime error occurs

  2. The program fails to compile

  3. The closest match is called if possible

  4. A default version of the function is generated and called

The correct answer is: The closest match is called if possible

When an overloaded function is called but doesn't match any of the overloaded functions exactly, C++ will attempt to find the closest match. This means that the program does not fail to compile or generate a runtime error, as options B and A suggest. Similarly, while it may generate a default version of the function, this is not always the case and does not accurately describe what happens in this situation. Thus, option D is incorrect. The closest match being called can also happen even if there are multiple overloaded functions that are equally close, as long as they are closer than any other options. This makes option C the best choice.