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

Answers were Sorted based on User's Feedback



In what cases using of a 'template' is a better approach then using of a 'base clas..

Answer / ashwini kumar

Template is used when you have to use different data types
in a single Class.In run time compiler alloate memory for
data.Template is also used to reduce the complicity of any
program,But in base class Complexity is high in larger
program,because you have to create different class for
passing different data types.In template you can create
only one.

Is This Answer Correct ?    3 Yes 0 No

In what cases using of a 'template' is a better approach then using of a 'base clas..

Answer / 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

In what cases using of a 'template' is a better approach then using of a 'base clas..

Answer / nishikant sahu

You can judge the need of Template and base class based on
following rule of thumb..
When operation(Method) doesn't affect on changing the data
type, use template.for ex when you want to write the stack
class of different data TYPE(int, bool,flaot) PUSH & POP
method doesn't affect on changing the data TYPE so in this
case you have to use TEMPLATE instead of Inheritance.
When operation(Method) does affect on changing the data
type, use Inheritance(base class).

Is This Answer Correct ?    2 Yes 0 No

In what cases using of a 'template' is a better approach then using of a 'base clas..

Answer / guest

if want to reduce the complexity of our program then we use
templates instead of base class. mainly it is used in
larger programs.

Is This Answer Correct ?    0 Yes 0 No

In what cases using of a 'template' is a better approach then using of a 'base clas..

Answer / samreen

templet is in the form of tag but classes are simple.

Is This Answer Correct ?    0 Yes 1 No

In what cases using of a 'template' is a better approach then using of a 'base clas..

Answer / murali

for Container kind of code

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More STL Interview Questions

Name the different types of stl containers.

0 Answers  


What is stl in oop?

0 Answers  


What is 2*2?

7 Answers  


What are stl algorithms?

0 Answers  


differentiate between private, public and protected data members of the class using example.

1 Answers  


help me i need a c++ program which takes sequesnce of characters and outputed sequence of their token taypes, work same compiler in lexical analysis phase

0 Answers  


WHAT IS FIBONACCI SERIES?

4 Answers   Stewart,


What is Object Oriental Progam

2 Answers  


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 ....

0 Answers   Microsoft,


Distinguish between: a) Normal layout & Print Layout views b) Windows Clipboard & office Clipboard c) Save & Save As Commands d) Program File & Data File e) Pie Charts & Barr Charts

0 Answers  


What is C++ could you enplane me please?

1 Answers  


What is a standard template library (stl)? What are the various types of stl containers?

0 Answers  


Categories