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

Which of the Standard C++ casts can be used to perform a ?safe? downcast: a) reinterpret_cast b) dynamic_cast c) static_cast d) const_cast

2 Answers   Quark,


What are maps in c++?

0 Answers  


Why do we use using namespace std in c++?

0 Answers  


What are the two main components of c++?

0 Answers  


Do vectors start at 0?

0 Answers  






Copy Linked List using recursive function?

2 Answers   Persistent,


What do you mean by function and operator overloading in c++?

0 Answers  


How many types of casting are there in C++? When is a dynamic cast,static_cast,reinterpret cast used?

2 Answers   CTS,


Is c++ a software?

0 Answers  


What is c++ namespace?

0 Answers  


Write a program to show polymorphism in C++?

0 Answers   Impetus, Verifone,


What is the basic of c++?

0 Answers  


Categories