GeekInterview.com
Series: Subject: Topic:
Question: 179 of 267

without using function overloading how can do the same job?

Asked by: Interview Candidate | Asked on: Jul 17th, 2006
Showing Answers 1 - 3 of 3 Answers
Yashwant Pinge

Answered On : Aug 30th, 2006

This can be achieved by using template.
For ex. template T mul( T a, T b);

Yes  1 User has rated as useful.
  
Login to rate this answer.
satyam

Answered On : Dec 18th, 2006

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.

  
Login to rate this answer.
praveennext

Answered On : Jan 3rd, 2007

View all answers by praveennext

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...

Yes  1 User has rated as useful.
  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.