Search code examples
c++gtkmm

Why can't i call remove() on Gtk::EventBox?


For some reason that is beyond me this doesn't work:

Gtk::EventBox *eb;
// ...
eb->foreach([eb](Gtk::Widget& w){ eb->remove(w); });

The error that i am getting is:

ImageClick.cpp: In lambda function:
ImageClick.cpp:20:50: error: no matching function for call to ‘Gtk::EventBox::remove(Gtk::Widget&)’
    eb->foreach([eb](Gtk::Widget& w){ eb->remove(w); });
                                                  ^
ImageClick.cpp:20:50: note: candidate is:
In file included from /usr/include/gtkmm-3.0/gtkmm/window.h:31:0,
                 from /usr/include/gtkmm-3.0/gtkmm/dialog.h:30,
                 from /usr/include/gtkmm-3.0/gtkmm/aboutdialog.h:33,
                 from /usr/include/gtkmm-3.0/gtkmm.h:99,
                 from ImageClick.cpp:1:
/usr/include/gtkmm-3.0/gtkmm/bin.h:141:8: note: void Gtk::Bin::remove()
   void remove();
        ^
/usr/include/gtkmm-3.0/gtkmm/bin.h:141:8: note:   candidate expects 0 arguments, 1 provided

But if i change it to eb->Gtk::Container::remove(w); it works as expected. Documentation shows that Gtk::EventBox is a subclass of Gtk::Container, and it is not a virtual function, nor is it overwritten anywhere. So what is the reason for such a behaviour?


Solution

  • It appears that it is a normal operation of C++

    container.h

    virtual void on_remove(Widget* widget);
    

    bin.h

    void remove();
    

    and eventbox.h doesn't have this function defined.

    Trying to recreate this scenario:

    #include <iostream>
    
    class A
    {
    public:
        void foo(int) { std::cout << 'A' << std::endl; }
    };
    
    class B : public A
    {
    public:
        void foo() { std::cout << 'B' << std::endl; }
    };
    
    class C : public B
    {
    };
    
    int main()
    {
        C c;
        c.foo(5);
    }
    

    The code above generates the exact same error. It appears that the name stops any further lookup. I was aware of shadowning, but didn't know this has happened when the shadowing function actually doesn't fit even with all the thunks in the world.