When is a template a better solution than a base class?
Answer / 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 |
What is Object Oriented programming.what is the difference between C++ and C?
What is the use of setprecision in c++?
What is flush () in c++?
What is difference between n and endl in c++?
Is java as fast as c++?
what is the use of Namespace in c++.
What is operators in c++?
Is there finally in c++?
Define virtual constructor.
Eplain extern keyword?
What are the important differences between c++ and java?
What is ios :: in in c++?