ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  STL
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
In what cases using of a 'template' is a better approach 
then using of a 'base class'?
 Question Submitted By :: Jayant
I also faced this Question!!     Rank Answer Posted By  
 
  Re: In what cases using of a 'template' is a better approach then using of a 'base class'?
Answer
# 1
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
Guest
 
  Re: In what cases using of a 'template' is a better approach then using of a 'base class'?
Answer
# 2
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 ?    0 Yes 0 No
Ashwini Kumar
 
 
 
  Re: In what cases using of a 'template' is a better approach then using of a 'base class'?
Answer
# 3
templet is in the form of tag but classes are simple.
 
Is This Answer Correct ?    0 Yes 0 No
Samreen
 
  Re: In what cases using of a 'template' is a better approach then using of a 'base class'?
Answer
# 4
for Container kind of code
 
Is This Answer Correct ?    0 Yes 0 No
Murali
 
  Re: In what cases using of a 'template' is a better approach then using of a 'base class'?
Answer
# 5
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 ?    0 Yes 0 No
Atul Jawale
 
  Re: In what cases using of a 'template' is a better approach then using of a 'base class'?
Answer
# 6
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 ?    0 Yes 0 No
Nishikant Sahu
 

 
 
 
Other STL Interview Questions
 
  Question Asked @ Answers
 
Define the terms: field, record, table and database  1
what's the difference between function overloading and function overiding?  2
what is strcture i++ i ++i answer to this i=5 what is the out put  5
What is the underlying datastructure of map? Siemens4
if 4-5 year old brother is standing on d roof with me and watching d moon, suddenly moon coverd by cloud then how will i explain d hiding of moon to my brother. MBT6
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?"  2
Find the error in the following program struct point {struct point *next; int data; } x; main() {int...data; } x; main() {int i; for(x=p;x!=0;) x=x->next,x++; freelist(x); } freelist(x) {free(x); return } Sun-Microsystems1
how to swap two numbers in a linked list without exchanging the data but only the links? Wipro2
what is an algorithm in terms of STL? Wipro1
In what cases using of a 'template' is a better approach then using of a 'base class'? Lucent6
What is the Difference between CArray and CList? Siemens1
What is Object Oriental Progam  1
Which data structure gives efficient search? A. B-tree B. binary tree C. array D. linked list Sun-Microsystems15
What is Template Specialization? Lucent1
Give the output of the following program main() {char *p='a'; int *i=100/*p; } what will be the value of *i= 1 Sun-Microsystems3
Difference between Structure and Class in C++? Caritor1
How Find, Replace and Go To commands ca be used to substitute one character string for another? Explain with the heIp of an example.  1
what's the difference between abstract class and concreate class? what's the meaning of standard template library(STL)?  3
I am doing my BS.c MATHS CAN I ABLE TO JOIN IN NIIT?  1
c# support late binding or early binding.  3
 
For more STL Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com