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

Can we use stl in coding interviews?

0 Answers  


Question 1)Read the data from one file and remove all the duplicated words and generate an output file containg only using words.Program should also print number of occurance of each words on standard output.(Program must be use STL and iostream object). Question 2)Write a program to convert the lower case contents of file to upper case using STL. Question 3)What is the output of this problem. int i=12; int &r =i; r+r/4; int +p =&r; int *p = &r; P+=r; return 1; Answer :a)12 b)17 c) 30 d)24 E)15 Question 4) #include #include #include void main() { char srcstr[30],desstr[30]; int i,len; clrscr(); cout<<"\nenter the string\n"; cin>>srcstr; len=strlen(srcstr); for(i=0;srcstr[i]!='\0';i++) { desstr[--len]=srcstr[i]; } desstr[i]='\0'; cout<<"\nreversed string is\n"; for(i=0;desstr[i]!='\0';i++) { cout< } getch(); } Answer : A) string output b)tuptuo gnirts c) string d)output Question 5) Class Test { static const Tk=LEN; int q; public: foo(intx =LEN):q(x){}; TGet Q() const { return q:} void call test Foo<long :9> foo(10); std::const<< foo.Getq(); Answer: 7,8,9,10,11 question 6) class A { int a; char b; }; class B:public A { char b; int a; }; What is the size? Answer a)5 bytes for class A and 5 bytes class B b)4 bytes for class A and 8 bytes class B. c).... d)....

2 Answers   Bally Technologies,


Give two integer arrays A & B.A has n elements and B has ' n-1 ' elements . A has all the elements that are there in B. But B has one missing element. Write a function that takes arrays , A & B as imnput and finds the missing element in most optised manner .

4 Answers   Zycus Infotech,


Explain when u will use Observer pattern and how u will implement in c++ .

1 Answers  


give me the defination of inheritance?

5 Answers   Infosys,






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

0 Answers   NDS,


how to use C++?

0 Answers   NIIT,


5. Write c++ function that would intake a string and return the number of occurrences of a given character in that sring Ex:- if the word is “Colombo” and count the occurrences of the letter “o” the function would return 3

1 Answers  


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

1 Answers  


write a program to search and display the position of an element in a single-dimentional array using function.

1 Answers  


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.

0 Answers  


Write a program in C++ returning starting locations of a substring using pointers

1 Answers  


Categories