Hello everyone,

I have a problem and almost found a solution, for example this: http://www.parashift.com/c++-faq-lite/multiple-inheritance.html. However in my case I cannot solve it in a proposed way and will explain it shortly why...

So basically, I have a BaseView, that derives from QWidget like this:

class BaseView:
   public QWidget
{
   BaseView(const QString &name){_name=name};
   void setName(QString &name){_name=name};
   QString &name(){return _name};
private:
   QString _name;
}

I want it, by default, to be a QWidget (graphical widget), because I'm using all the ...View classes in some graphical container - they are cast on to BaseView and put into a graphical grid.
And I want other people to make their own classes, which by default are derived from QWidget (when not declaring anything else) or for example QPushButtons, what would be something like this:

class PushButtonView:
   public BaseView,
   public QPushButton
{
   PushButtonView(const QString &name){_name=name};
}

But here comes a problem, because QPushButton is also derived from QWidget (reference to some members is ambiguous). I end up with diamond structure like this:

QWidget
                          /          \
                         /            \
               BaseView       QPushButton
                        \             / 
                         \           /
                       ButtonView

I cannot do something that was suggested in a link mentioned before (virtual classes), 'cause QWidget is not my class and I can't alter it. Does anyone have some idea, how I can overcome this problem?

Thank You in advance,
Krzysztof.

If this is QT then the QT documentation specifically says that you must only inherit from QObject once and QObject is a base class of QWidget.

You will have to break the diamond. That might mean having a abstract class that BaseView and ButtonView both inherit from that does no inherit QWidget and not having ButtonView inherit from BaseView.

Thank You for Your suggestions. Not happy with the result, but have to smohow deal with it.

All the best!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.