When is a template a better solution than a base class?



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

Post New Answer

More C++ General Interview Questions

What is Object Oriented programming.what is the difference between C++ and C?

8 Answers   Infosys,


What is the use of setprecision in c++?

0 Answers  


What is flush () in c++?

0 Answers  


What is difference between n and endl in c++?

0 Answers  


Is java as fast as c++?

0 Answers  






what is the use of Namespace in c++.

3 Answers  


What is operators in c++?

0 Answers  


Is there finally in c++?

0 Answers  


Define virtual constructor.

0 Answers  


Eplain extern keyword?

0 Answers  


What are the important differences between c++ and java?

0 Answers  


What is ios :: in in c++?

0 Answers  


Categories