Reputation: 10273
I have this setup:
class A
{
public:
virtual void Function();
}
class B : private A
{
}
class C : public B
{
public:
// I want to expose A::Function() here
}
I tried to do this by adding:
class C : public B
{
public:
virtual void Function();
}
and
C::Function()
{
A::Function();
}
but I get and "inaccessible base" error.
Is it possible to do something like this?
Upvotes: 1
Views: 132
Reputation: 355187
In B
you can change the accessibility of A::Function
to protected
:
class B : private A
{
protected:
using A::Function;
};
In C::Function
(and elsewhere in C
) you will then have to refer to the function as B::Function
, not A::Function
. You could also public: using B::Function;
in C
instead of implementing a C::Function
that just calls B::Function
.
Upvotes: 5
Reputation: 11531
Not really. The scenario you're describing would indicate that your class hierarchy needs to be reworked.
Upvotes: 0
Reputation: 146968
You can't do this. The fact that B
inherits from A
is an implementation detail and you are not allowed to access it from C
- just like you can't access B
's private functions or member variables.
This would be completely legal if B
inherited protected
or public
from A.
Upvotes: 3