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 setw manipulator in c++?
Explain the auto storage classes in c++.
What is a constant? Explain with an example.
Please explain class & object in c++?
What return value must conversion operators have in their declaration?
Are there any special rules about inlining?
What is null c++?
Can we get the value of ios format flags?
what is a reference variable in C++?
What's the hardest coding language?
What's the "software peter principleā?
When do we run a shell in the unix system?
What jobs can you get with a c++ certification?
Explain the static member function.
Define private, protected and public access control.