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

How do you convert stl to steps?

826


Is stl open source?

836


Name the different types of stl containers.

893


What is the use of stl?

819


write a program that will accept a number and print.its equivalent in words the maximum input number is 9999

2695


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

2119


Who created stl?

854


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

3087


Define stl.

1018


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

2266


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

900


What is a standard template library (stl)?

824


What are stl algorithms?

850


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

2128


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

2094