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

Explain how to insert a hyperlink in to an Excel worksheet and save a Word document as a Web page.

1 Answers  


draw a flowchart that accepts two numbers and checks if the first is divisible by the second.

0 Answers   Appin, NIIT,


Is there any error below, its a code to delete all entires from a map #include <map> #include iostream.h int main() { int i =0; map <int, char> TestMap; while(i<3) { TesMap.insert(TestMap::value_type(i,Test)); i++; } typedef map<int, char> :: iterator mapIter =TestMap.begin(); if(mapIter!=TestMap.end()) { TestMap.erase(mapItrer); ++mapIter; } return 0; }

0 Answers  


What is the stl, standard template library?

0 Answers  


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

0 Answers  






What is a standard template library (stl)?

0 Answers  


why does the execution of a c++ program start with main()???

11 Answers  


a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.

0 Answers  


What are the components of stl?

0 Answers  


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

0 Answers  


What is the STL?

2 Answers   Epson, HP,


Describe how to safeguard a system through acquisition of an antivirus Program and systematic backup.

0 Answers  


Categories