Can we overload a function based on only whether a parameter is a value or a reference?
Posted
by skydoor
on Stack Overflow
See other posts from Stack Overflow
or by skydoor
Published on 2010-03-16T20:59:22Z
Indexed on
2010/03/16
21:01 UTC
Read the original article
Hit count: 106
c++
I got the answer NO! Because passing by value and passing by reference looks identical to the caller.
However, the code below compiles right
class A {
public:
void f(int i) {}
void f(int& i) {}
};
But when I try to use it, there is compile error.
int main () {
A a;
int i = 9;
int& j = i;
a.f(1);
a.f(i);
a.f(j);
return 0;
}
Why does not the compiler disable it even without knowing it is going to be used?
© Stack Overflow or respective owner