It looks like that there is something that I don't understand about multiple inheritance and abstract methods. I am implementing some hardware functionality in SystemC, with multiple target HWs. I have two different levels of software implementation. The first one is optimized for performance; the second one on its top, has some display, etc. functionality. [Note, in the hardware world "top" refers to the highest level instance which is usually a wrapper or a testbench for the hardware instance]
To actually handle a HW, in scSW I implemented "Hold()". When I want to use it in the higher level (see SW and SW2), my compiler said
error: ‘scHW’ is an ambiguous base of ‘SW’
struct SW : scSW, HW { virtual bool Holds(){return scHW::Holds();} };
and
invalid new-expression of abstract class type ‘SW2’
SW2* S2 = new SW2;
^~~
because the following virtual functions are pure within ‘SW2’:
struct SW2 : scSW, HW { };
It also added:
request for member ‘Holds’ is ambiguous
std::cerr << S2->Holds();
I especially do not see, how can a method be pure and ambiguous, at the same time? What do I wrong and what is the correct way of coding what I want?
#include <iostream>
struct Virtual { virtual bool Holds() = 0;};
struct scHW { bool Holds(){return true;}};
struct scSW : scHW, Virtual {};
struct HW : scHW { };
struct HW2 : scHW { virtual bool Holds(){return scHW::Holds();}};
struct SW : scSW, HW { virtual bool Holds(){return scHW::Holds();} };
struct SW2 : scSW, HW { };
int main()
{
HW* H = new HW;
HW2* H2 = new HW2;
scHW* H1 = new scHW;
SW* S = new SW;
SW2* S2 = new SW2;
std::cerr << S->Holds();
std::cerr << H->Holds();
std::cerr << H2->Holds();
std::cerr << S2->Holds();
}