Given
#include <iostream>
#include <string>
using std::cout;
using std::endl;
class A
{
public:
virtual int a() const = 0;
virtual int a(const int i) const = 0;
};
class B : public A
{
public:
virtual int a() const { return A::a(0); }
};
class C : public B
{
public:
virtual int a(const int i) const { return i; }
};
int main()
{
C c;
cout << c.a() << endl;
cout << c.a(1) << endl;
}
I did not tests with different compilers but i have the following errors:
main.cpp:31:17: error: no matching function for call to ‘C::a()’
cout << c.a() << endl;
^
main.cpp:24:17: note: candidate: virtual int C::a(int) const
virtual int a(const int i) const { return i; }
^
main.cpp:24:17: note: candidate expects 1 argument, 0 provided
I do not understand really why, I was expecting that class C can access at B::a().
It seems that is resolving the C.a() as C.a(int). Basically the virtual method from B is not visible. Anyone knows why?
EDIT
The idea is something like: A as "interface", B as "abstract class", C the "concrete class"
SOLUTION
What i was trying to achieve is possible with using A::a using B::a and changing the B::a() call from A::a(0) to a(0).
Like the example here provided by songyuanyao