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.


Why might virtual functions be used sparingly in a design according to the text?

  1. They make code harder to read

  2. They can introduce runtime errors

  3. They are not supported in all compilers

  4. They introduce runtime overhead

The correct answer is: They introduce runtime overhead

Virtual functions are used sparingly because they introduce runtime overhead, which can negatively affect the performance of a program. This is because virtual functions require an extra layer of lookup at runtime to determine the appropriate function to call, which can slow down the execution of the code. Options A, B, and C are incorrect because virtual functions do not directly contribute to these issues. Option A is incorrect because the use of virtual functions does not inherently make code harder to read. Option B is incorrect because virtual functions do not necessarily introduce runtime errors, but they may make it more difficult to debug these errors. Option C is incorrect because virtual functions are a language feature and are generally supported by most compilers. Ultimately, the decision to use virtual functions sparingly is based on their impact on runtime performance, not on issues related to code readability, runtime errors, or compiler support.