So, my class hierarchy looks something like this:
QObject QGraphicsPolygonItem
\ /
\/
CBubble
/\
/ \
CListBubble CSingleLinkBubble
\ /
\/
CActionBubble
The reason I'm doing multiple inheritance is because I have another bubble that is a CListBubble (LB), but not a CSingleLinkBubble (SB).
The error I receive is "CBubble is an ambiguous base of CActionBubble".
- I've tried the virtual tag on one or both of them.
- I've tried adding "virtual CBubble" to CActionBubble.
- I've tried changing to "public virtual CBubble" in LB and SB, but that causes issues in all bubbles that inherit from them.
I could forego CListBubble entirely and copy/pasta the code, but that goes against all my instincts. I could try to refactor this to use the decorator pattern, but that seems like a lot of unnecessary work for this one case.
Any help or suggestions are much appreciated. Thanks.
EDIT:
I apologize, should have read the MCVE rules.
Note - I just typed this up now, so hopefully there aren't any syntax issues, but I assume it gets the point across.
clistbubble.h
// header guard
#include "cbubble.h"
class CListBubble : public CBubble
{
public:
CListBubble(const QPointF & pos, QGraphicsItem *parent = 0);
// data members/methods
};
clistbubble.cpp
#include "clistbubble.h"
CListBubble(const QPointF & pos, QGraphicsItem *parent)
: CBubble(pos, parent) // rest of base member initialization
{
// other stuff for this type of bubble
}
// Other methods
The header for CSingleLinkBubble is equivalent in all but members and methods.
cactionbubble.h
// header guard
#include "csinglelinkbubble.h"
#include "clistbubble.h"
class CActionBubble : public virtual CSingleLinkBubble, public virtual CListBubble
{
public:
CActionBubble(const QPointF & pos, QGraphicsItem *parent);
// data members/methods
};
cactionbubble.cpp
#include "cactionbubble.h"
CActionBubble(const QPointF & pos, QGraphicsItem *parent)
: CSingleLinkBubble(pos, parent), CListBubble(pos, parent) // rest of base member initialization
{
// other stuff for this type of bubble
}
I'm concerned that the issue lies in the constructor of CActionBubble where both parent classes are called. However both calls are necessary and would happen anyway if I implemented a default ctor.
The error points me to the place I attempt to new a CActionBubble. "CBubble is an ambiguous base of CActionBubble"
I also forgot to mention that CBubble inherits from QObject so I can implement signals and slots. I read something awhile back that multiple inheritance with QObject is not possible. Could it be that this is the actual issue, and the error just points one layer below?