see please the code:
#include <iostream>
using namespace std;
class A{
public:
A() = default;
virtual void foo() = 0;
bool foo(int x)
{
cout<<"A::foo(int x)\n";
return true;
}
bool func(int x)
{
cout<<"A::func(int x)\n";
return true;
}
};
class B: public A
{
public:
B() = default;
void foo()
{
cout<<"B::foo()\n";
}
};
int main()
{
B b;
b.func(0);
//b.foo(0); //it's not compiled
b.A::foo(0);
return 0;
}
It seems the parent's method should be called explicitly with the parent's prefix from the child object for any reason. b.foo(0)
is not compiled but if I add A:: prefix like b.A::foo(0)
it works.
Why is b.foo(0)
not compiled but b.func(0)
is?