Calling same function with different number of parameters

HI

I want to call same function with different number of parameters. i know we can call same method with diffrent type of parameters but i need with different number of parameters.

like

myfunction ( para1, para2 para3);

myfunction (para1, para2);
What behavior do you expect from myfunction() when para3 is missing?
Actually para3 is returning variable. if any one has no need of returning value of particular parameter. then he can miss in the function call. i want to keep it more general.
Then you probably should have two functions:

1
2
3
4
5
6
7
8
9
10
myfunction(para1, para2, para3)
{
    ...
}

myfunction(para1, para2)
{
    para3;
    return myfunction(para1, para2, para3);
}
two options:

1) use a default parameter

1
2
3
4
void myfunction(int a, int b, int c = 0)
{
  // calling myfunction(1,2)  would be the same as calling myfunction(1,2,0)
}


2) overload the function
1
2
3
4
5
6
7
8
9
void myfunction(int a,int b)
{
  // called if only 2 params given
}

void myfunction(int a, int b, int c)
{
  // called if all 3 params given
}
Topic archived. No new replies allowed.