Let's consider two classes A
and B
with the following interface:
class A {
public:
virtual void start() {} //default implementation does nothing
};
class B {
public:
void start() {/*do some stuff*/}
};
and then a third class which inherits from both, A
publicly because it implements this "interface", and B
privately because that's implementation detail.
However, in this specific implementation, start()
only has to contain a call to B::start()
. So I thought I could use a shortcut and do the following:
class C: public A, private B {
public:
using B::start;
};
and be done with it, but apparently it doesn't work. So I get using
private base function doesn't work in order to override virtuals. From that, two questions:
- Is there any way to make this work as I supposed it may have worked?
- Why would the compiler accept this code as valid? As I see it there are now two
start()
functions with the exact same signature inC
and yet the compiler seems fine with it and only callsA::start()
.
EDIT: A few precisions:
- The goal is to manipulate
C
objects throughA
pointers. - I'm currently using a simple function that just calls
B::start()
, I was specifically wondering if a using declaration could indeed "override" a virtual, and if not, how this was allowed to have both functions coexist. - I might have omitted a few things like
virtual
inheritance for simplicity.