Question { Wipro, 10984 }
In what cases using of a 'template' is a better approach
then using of a 'base class'?
Answer
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.