Re: Diamond inheritance with Gtk::Widget as a virtual base



Thank you for your answer. You are right, my problem is coming from container who doesn't virtually inherit from Widget. I decided that Database and MYSQL will both virtually inherit from Gtk::Box.

Regards
Quentin

Le 18/12/2015 18:38, Kjell Ahlstedt a écrit :
Gtk::HBox is deprecated. You should use Gtk::Box instead.

I'm not quite sure, but I think the problem is that that GUI::MYSQL::Database inherits from Gtk::Widget via two paths, and only in one path is Gtk::Widget a virtual base class. GUI::Database inherits virtually, but Gtk::HBox does not. More specifically:
  namespace Gtk {
    class Container : public Widget  // not virtual
    class Box : public Container
    class HBox : public Box
  }

Kjell

Den 2015-12-18 kl. 12:48, skrev Quentin Huot-Marchand:
Hello,
I am Quentin and I work on a project who should be modular. For that I designed a simple way to add more "database".
Here a uml graphic of what I try to do:
                                                          ____________
                                                         | Gtk::Widget|
                                                         |----------------|
                                                         |____________|
                                                            /\       /\
                                                           /__\   /__\
                               ___________________|       |  
                              |                                       |  
 _________              |                             _______|___
| Window| 1           |                     0..* | Database |
|----------- | --------------------------------- |---------------|
|_________|             |                            |___________|
                             |                                    /\
                             |                                  /__\
                   ______|_____                            |
                  |  Gtk::HBox |             _________|__________
                  |----------------|            | MYSQL::Database |
                  |____________|            |-------------------------|
                          /\                       |___________________|
                        /__\                                   |
                          |_______________________|

My goal is to easily add different Database UI
I tried to use resources from http://www.cprogramming.com/tutorial/virtual_inheritance.html and from http://www.cprogramming.com/tutorial/virtual_inheritance.html
So in C++ I've got this

MYSQL::Database

namespace GUI {
namespace MYSQL {

class Database : public virtual Gtk::HBox, public GUI::Database {
public:
    Database(std::string name);
    virtual void save() ;
    virtual Gtk::Widget & getToolbar() ;

    virtual void destroy_notify_() { GUI::Database::destroy_notify_(); }
    virtual void set_manage() { Gtk::HBox::set_manage(); }
private:
    Gtk::Toolbar mToolbar ;
    Gtk::Label mLabel ;
};

}
}

With
MYSQL::Database::Database(std::string name) : Widget(), HBox(), GUI::Database(name),
    mToolbar(), mLabel("hello") {
    this->pack_start(mLabel) ;
    this->show_all_children();
}

Database:

namespace GUI {

class Database : public virtual Gtk::Widget {
public:
    Database(std::string name);
    std::string getName() const { return mName ; }
    virtual void save() = 0 ;
    virtual Gtk::Widget & getToolbar() = 0;
    virtual void destroy_notify_() { }

    Database(Database const&) = delete;
    void operator=(Database const&) = delete;
private:
    std::string mName ;
};

}

with
Database::Database(std::string name) : Widget(), mName(name) {
}

And I've this compilation error:

In file included from /home/spartan-117/Documents/NSS/DBConceptor/GUI/src/main_window.cpp:5:0:

/home/spartan-117/Documents/NSS/DBConceptor/GUI/include/mysql/database.h:12:7: warning: virtual base 'Gtk::Widget' inaccessible in 'NSS::DBConceptor::GUI::MYSQL::Database' due to ambiguity [-Wextra]

class Database : public virtual Gtk::HBox, public GUI::Database {

^

/home/spartan-117/Documents/NSS/DBConceptor/GUI/src/main_window.cpp: In member function 'void NSS::DBConceptor::GUI::MainWindow::newDatabase()':

/home/spartan-117/Documents/NSS/DBConceptor/GUI/src/main_window.cpp:73:33: error: 'Gtk::Widget' is an ambiguous base of 'NSS::DBConceptor::GUI::MYSQL::Database'

this->mMainBox.pack_start(*dab);

If you could help me I'll be really happy.

Regards, Quentin Huot-Marchand






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]