有人可以解释一下这里发生了什么。为什么编译器在 A 类中看不到没有参数的 hello()?
struct A {
virtual void hello() {}
virtual void hello(int arg) {}
};
struct B : A {
virtual void hello(int arg) {}
};
int main()
{
B* b = new B();
b->hello();
return 0;
}
g++ main.cpp
main.cpp: In function ‘int main()’:
main.cpp:13:11: error: no matching function for call to ‘B::hello()’
main.cpp:13:11: note: candidate is:
main.cpp:7:15: note: virtual void B::hello(int)
main.cpp:7:15: note: candidate expects 1 argument, 0 provided