overloaded function with reference paramater

hi

assume that we have two overloaded function but the different between them is the first
1
2
3
4
int function ( int x,int y)
{
//some code  
}

but the second is
1
2
3
4
int function ( int &x,int &y)
{  
//some code 
}

does it work ?
i checked this situation in gcc compiler and it acceptes it
but the turbo borland 4.5 don't , what is the standard rules about this case?
can we have two function with same number , type and order of parameters but the different between thim is the second one have reference variable and the first don't ??
Last edited on
I think that you can compile the two functions and the first one should work fine with numerics function( 2 ); but if you pass a variable, the compiler should get an ambiguity error
1
2
int n=2;
function( n ); // compiler doesn't know which to use 
Last edited on
Yeah what Bazzy says is right. It's a bit strange though to do what you are trying to do. The whole point of overloading is to let the compiler decide which function to call, but in your case, one function intends to modify its arguments and the other not, so it seems like the caller truly cares which one gets called.

Topic archived. No new replies allowed.