Without using function overloading how can do the same job?

Showing Answers 1 - 7 of 7 Answers

Yashwant Pinge

  • Aug 30th, 2006
 

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

satyam

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

  Was this answer useful?  Yes

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

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions