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 |
Explain static and dynamic memory allocation with an example each.
What do you mean by function pointer?
Which is best c++ or java?
Describe the main characteristics of static functions?
If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?
What are the various arithmetic operators in c++?
What are the different data types present in C++?
How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?
What is the hardest coding language to learn?
Is multimap sorted c++?
Is it possible to have a recursive inline function in c++?
what is the behaviour of C and C++ compiler for the below statements. int *p; p = malloc(100); Is the behaviour same ? or different ?