When is a template a better solution than a base class?
Answer Posted / neelkamal yadav
When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or management, and particularly when those other types are unknown (thus, the genericity) to the designer of the container or manager class.
Prior to templates, you had to use inheritance; your design might include a generic List container class and an application-specific Employee class. To put employees in a list, a ListedEmployee class is multiply derived (contrived) from the Employee and List classes. These solutions were unwieldy and error-prone. Templates solved that problem.
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the use of register keyword with the variables?
What is an iterator?
Explain container class.
Which bit wise operator is suitable for turning off a particular bit in a number?
What is a class template in c++?
Is c better than c++?
How to declare an array of pointers to integer?
What is a driver program?
Where can I run c++ program?
How do you clear a buffer in c++?
What is a manipulator in c++?
What is while loops?
What does flush do?
Define 'std'.
What is atoi?