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
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 |
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 |
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 |
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 |
Answer / samreen
templet is in the form of tag but classes are simple.
| Is This Answer Correct ? | 0 Yes | 1 No |
To modify an, existing worksheet. What steps are involved for: 1. Inserting and deleting rows and columns. 2. Printing cell formulas 3Jld displayed values 3. Using the page setup command
Describe the My Computer and My Documents folders; identify the elements that are present in every Window.
How can you create a bulleted list, numbered list and an outline by using bullets and numbering command. Explain with the help of example.
what is the acronym of the term 'C.O.M.P.U.T.E.R' ?
17 Answers Config Systems, Google, Wipro,
method overloading means what?
give me the defination of inheritance?
write a c++ to define a class box with length,breadth and height as data member and input value(),printvalue() and volume() as member functions.
Assume I have a linked list contains all of the alphabets from "A" to "Z?" I want to find the letter "Q" in the list, how does you perform the search to find the "Q?"
HOW TO GET "H1B" -VISA 4 USA FOR MY SON?HE HAD COMPLETED "MS"(IT)FROM AUSTALIA 2007.I AM WORKING IN U.S.A.
What do stl stand for?
What is Object Oriental Progam
In what scenario does the Logical file and Physical file being used?