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!

Practice this question and more.


According to the text, what mechanism does C++ use to solve multiple independent class hierarchies problem?

  1. Dynamic memory allocation

  2. Object-based inheritance

  3. Templates

  4. Static global arrays

The correct answer is: Templates

C++ uses templates to solve the problem of multiple independent class hierarchies because templates allow for the creation of generic classes and functions that can be used with different types of data. This eliminates the need for creating separate, independent class hierarchies for each type of data. Option A, dynamic memory allocation, is a mechanism for allocating memory at runtime and is not directly related to solving multiple class hierarchy problems. Option B, object-based inheritance, is a type of inheritance that allows for the reuse of code and data from one class to another, but does not specifically address independent class hierarchies. Option D, static global arrays, is a data structure and not a mechanism for solving class hierarchy problems. Therefore, the correct answer is C templates.