I have a class C
that privately inherits B
that implements an interface A
, as shown below:
class A {
public:
virtual void f() = 0;
virtual void g() = 0;
};
class B: public A {
public:
void f() override {};
void g() override {};
};
class C: private B {
public:
using B::f;
};
My intention is that I want C
to act like B
, but only have access to B::f()
and not B::g()
.
I also have a function that take references to A
:
void use(A& a) {} // function that takes any object that inherits from A
My problem is that calling use()
with a C
object raises the following compilation error:
conversion to inaccessible base class "A" is not allowed
What is the correct way to allow C
to be converted into an A
?