I'm having trouble with a multiple inheritance usage case (it's not my project, I didn't decide the inheritance scheme, sorry). Anyway, I can't seem to call a protected virtual
member function from an overriding function. Here's a simplified class structure:
class Base {
protected:
virtual void foo() { }
};
class A: virtual public Base {
protected:
virtual void foo();
};
void A::foo() { printf("Hello A\n"); }
class B: virtual public Base {
protected:
virtual void foo();
};
void B::foo() { printf("Hello B\n"); }
class AB: public A, public B {
protected:
void foo();
};
void AB::foo()
{
A::foo();
B::foo();
}
I would expect that if I call AB
's foo()
, I'll get output that looks like
Hello A
Hello B
However, when I compile, I get an errors like:
error #308: function "A::foo" is inaccessible
A::foo();
^
error: a nonstatic member reference must be relative to a specific object
A::foo();
^
error #308: function "B::foo" is inaccessible
B::foo();
^
error: a nonstatic member reference must be relative to a specific object
B::foo();
^
Even if I make all of the foo
s public, I still see this. What's wrong?
AB::foo()
is not a member ofAB
, double check the signature is identical in your non-simplified version..void foo()
andvoid AB::foo()
are very different!