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 programming language should I learn first?
Which programming language's unsatisfactory performance led to the discovery of c++?
Is c++ vector dynamic?
Explain unexpected() function?
What is a storage class?
How does java differ from c and c++?
What is abstract class in c++?
What is the limitation of cin while taking input for character array?
Can we use this pointer inside static member function?
What is a c++ map?
What is the difference between interpreters and compilers?
Can constructor be private in c++?
What are the advantages of early binding?
Can turbo c++ run c program?
Explain about vectors in c ++?