GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 88 of 208    Print  
without using function overloading how can do the same job?

  
Total Answers and Comments: 3 Last Update: January 03, 2007     Asked by: geeta 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Yashwant Pinge
 
This can be achieved by using template.
For ex. template T mul( T a, T b);

Above answer was rated as good by the following members:
yzesong
August 30, 2006 07:20:14   
Yashwant Pinge        

RE: without using function overloading how can do the ...
This can be achieved by using template.
For ex. template T mul( T a T b);

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
December 18, 2006 01:43:03   
satyam        

RE: without using function overloading how can do the ...
To some extent this can be achieved by using default arguments for the func. But this also depends what all parameters you need to pass in different cases.
 
Is this answer useful? Yes | No
January 03, 2007 04:52:41   
praveennext Member Since: December 2006   Contribution: 2    

RE: without using function overloading how can do the ...

depends on the requirement. if you got fixed no of arguments like

sum(int int)
sum(float float) .. go for Templates.

If you have variable arguments and you know the data types then make use of va_list. ie variable argument list

define the function like sum(int x ... ) { //code }

In this you can call the function as sum(1 2 3) or sum(1) etc...


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape