J
James.Yu.Tin
Anybody can kindly explain the confusion below?
generally, would there be any problem for C++?
void magic(int& a) {
/* expect side-effect */
// change the value of the input
printf("by reference.");
return;
}
void magic(int a){
/* any side-effect is not allowed*/
printf("by value.");
return;
}
//each with a unique signature, so it is ok to have both magic(int& )
and magic(int), though they are overloaded;
//now comes the problem. when both magics are defined as above,
//none of them can be called without ambiguity. For example,
void main(){
int x = 10000;
magic(x);
}
generally, would there be any problem for C++?
void magic(int& a) {
/* expect side-effect */
// change the value of the input
printf("by reference.");
return;
}
void magic(int a){
/* any side-effect is not allowed*/
printf("by value.");
return;
}
//each with a unique signature, so it is ok to have both magic(int& )
and magic(int), though they are overloaded;
//now comes the problem. when both magics are defined as above,
//none of them can be called without ambiguity. For example,
void main(){
int x = 10000;
magic(x);
}