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 mechanism does C++ provide for creating generic programming components?

  1. Inheritance

  2. Macros

  3. Templates

  4. Virtual functions

The correct answer is: Templates

C++ provides the use of templates for creating generic programming components. Inheritance, although a useful feature in object-oriented programming, does not provide the same level of reusability and flexibility as templates do. Macros, while they can be used for some generic programming purposes, are not specifically designed for this purpose and can lead to potential issues such as name conflicts and type safety concerns. Virtual functions, while also a useful feature in C++, are primarily used for polymorphic behavior and are not intended for generic programming. Therefore, the most suitable mechanism in C++ for creating generic components is the use of templates.