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

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

1698


Can we use stl in coding interviews?

1276


What do stl stand for?

638


Is stl part of c++ standard?

637


Why should a c++ programmer be interested in stl?

638






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

1881


Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister

1660


What is the stl, standard template library?

592


What are the various types of stl containers?

727


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

1642


What is stl stack?

658


Define stl.

773


What is a stl vector?

625


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

2091


Is stl open source?

629