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 are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random

0 Answers  


What is the main purpose of c++?

0 Answers  


How can you quickly find the number of elements stored in a static array?

0 Answers  


What is object in c++ wikipedia?

0 Answers  


Can char be a number c++?

0 Answers  






What are the data types in c++?

0 Answers  


Do class method definitions?

0 Answers  


What is the purpose of extern storage specifier?

0 Answers  


What is ios flag in c++?

0 Answers  


find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

0 Answers  


Name some pure object oriented languages?

1 Answers  


A prime number is a number which is divisible only by itself and 1. Examples of the first few primes are 2, 3, 5, 7, 11. Consider writing a program which can generate prime numbers for you. Your program should read in and set a maximum prime to generate and a minimum number to start with when looking for primes. This program should be able to perform the following tasks: 1. Read the maximum number from user (keyboard input) to look for primes. The program should not return any primes greater than this number. 2. Read the minimum number from user (keyboard input) to look for primes. The program should not return any primes less than this number. 3. Generate and print out every prime number between the maximum prime and minimum number specified by the user.

0 Answers  


Categories