In this sample inheritance hierarchy:
class I1
{
public:
virtual void a() = 0;
virtual void b() = 0;
};
class I2 : public I1
{
public:
virtual void c() = 0;
};
class AC1 : public I1
{
public:
virtual void a() { printf( "AC1::a()\n" ); }
};
class C1 : public AC1, public I2
{
public:
// using AC1::a; // *
// virtual void a() { AC1::a(); } // **
virtual void b() { printf( "C1::b()\n" ); }
virtual void c() { printf( "C1::c()\n" ); }
};
I1, I2 are interfaces, i.e. pure abstract base classes.
AC1 is an abstract class.
C1, in my opinion, should be a concrete class, but is not.
The problem: C1 does not implement method a(), inherited from its base
class
I2. In this case the C++ paradigm of using a pure abstract base class
does
not mimic exactly the functionality of a java interface. In java, the
fact
that C1's base class AC1 implements a() is enough.
As far as I can tell, the only way to make this work as expected is to
manually delegate any missing methods; for example, the **-marked
method
definition above. The * statement is enough to disambiguate between
AC1::a()
and I2::a(), but is not enough to consider AC1::a() an implementation
of
I2::a().
Is there something I am missing here? Is there no better way to
implement
(pun intended) interfaces in C++?