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 the difference between c++ and turbo c++?
Define copy constructor.
What is the difference between ++ count and count ++?
How can virtual functions in c++ be implemented?
How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?
Can a class be static in c++?
What is flush () in c++?
Is c++ harder than java?
When do you call copy constructors?
What are the types of STL containers?
What is the use of volatile keyword in c++? Give an example.
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.