In what cases using of a 'template' is a better approach
then using of a 'base class'?

Answer Posted / atul jawale

Template is a better approach than using of a base class if:
1. Multiple copies of code for different data types with
the same logic.
2. If a set of functions or classes have the same
functionality for different data types
Then, a class becomes good candidates for being written as
Templates.

One good area where this C++ Class Templates are suited
can be container classes. Very famous examples for these
container classes will be the STL classes like vector, list
etc., Once code is written as a C++ class template, it can
support all data types.

Though very useful, It is advisable to write a class as a
template after getting a good hands-on experience on the
logic.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different types of stl containers?

652


If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2. please answer my question ....

1778


What are the symptoms of stl?

607


How is stl different from c++ standard library?

746


Is stl part of c++ standard?

645






Is stl open source?

636


i wanted to know about questions about c,c++ , which is required for placements.... im a fresher

1702


What is stl in c++ with example?

634


What do stl stand for?

643


What is a stl vector?

628


write a program to convert a decimal number in to its equivalent binary number?

2084


What is a standard template library (stl)?

649


how can u do connectivity in c++ language? plz send me connectivity code in c++ ?

1897


sir please send me bpcl previous question papers

1961


What is stl in oop?

681