P
Peng Yu
Hi,
The following code doesn't work at the commented line. I'm wondering
why C++ grammar is defined this way. Shouldn't C++ be smarter enough
to figure out whether an member function or a free function shall be
used?
Thanks,
Peng
#include <iostream>
struct A {
A(int a) : _a(a) { }
int _a;
};
void doit(const A &a) {
std::cout << a._a << std::endl;
}
struct B {
public:
B(const A &a) : _a(a) { }
void doit() {
doit(_a);// the member function is conflicted with the free
function.
}
private:
A _a;
};
int main () {
B b((A(2)));
b.doit();
}
The following code doesn't work at the commented line. I'm wondering
why C++ grammar is defined this way. Shouldn't C++ be smarter enough
to figure out whether an member function or a free function shall be
used?
Thanks,
Peng
#include <iostream>
struct A {
A(int a) : _a(a) { }
int _a;
};
void doit(const A &a) {
std::cout << a._a << std::endl;
}
struct B {
public:
B(const A &a) : _a(a) { }
void doit() {
doit(_a);// the member function is conflicted with the free
function.
}
private:
A _a;
};
int main () {
B b((A(2)));
b.doit();
}