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 a c++ object?
Can class objects be passed as function arguments?
Write a program which uses functions like strcmp(), strcpy()? etc
What is struct c++?
Does c++ have foreach?
How static variables and local variablesare similar and dissimilar?
Is c# written in c++?
What is doubly linked list in c++?
how to connect with oracle 9i with server in socket program in c/c++
What is c++ try block?
What is std :: flush?
Are iterators pointers?
Is c++ a software?
What is general format for a prototype?
Why do we use iterators?