Hi all. I have a scenario where i have two interfaces, IA and IB. IB is an extension of IA. I also have two implementations of the said interfaces, AImpl and BImpl. I let BImpl inherit from AImpl in order to take care of the IA implementation part of IB. I have used this technique before in Java, but in C++ (VS and GCC), it seems like the IB methods inherited from IA needs to be re-implemented in BImpl, inheriting from AImpl does not help. Below is an example of what I mean:
This does not compile, since the compilers say that IB::m1 is not implemented
in BImpl. What I would like is for BImpl to inherit the implementation of m1 from AImpl, thus making BImpl indirectly implement IB::m1 (an thus all IB). This does not seem to work. What can I do to make this work?
Thank you in advance
Code:
#include <cstdio>
class IA { public: virtual void m1() = 0; };
class IB: public IA { public: virtual void m2() = 0; };
class AImpl: public IA {public: void m1() { printf("m1"); }};
class BImpl: public IB, public AImpl {public: void m2() { printf("m2"); }};
int main() { BImpl b; b.m2(); return 0; }
in BImpl. What I would like is for BImpl to inherit the implementation of m1 from AImpl, thus making BImpl indirectly implement IB::m1 (an thus all IB). This does not seem to work. What can I do to make this work?
Thank you in advance
Comment