i have a problem with function overloading while using const function and const object. Can someone explain why "const foo int& int" is being print instead of "foo int char&" in the following code?
struct A
{
void foo(int i, char& c) { cout << "foo int char&" << endl;}
void foo(int& i, int j) const { cout << "const foo int& int" << endl;}
};
int main() {
A a;
const A const_a;
int i = 1;
char c = 'a';
a.foo(i,i);
}
Thanks,
a.foo(i, c)? Otherwise, why is there ac?