1

when trying to create a custom menu class that is inherited from Gtk::Menu the following output containing invalid use of incomplete type is thrown

main.cc:5:28: error: invalid use of incomplete type ‘class Gtk::Menu’
    5 | class AppMenu: public Gtk::Menu
      |                            ^~~~
In file included from /usr/include/gtkmm-4.0/gtkmm.h:207,
                 from main.cc:1:
/usr/include/gtkmm-4.0/gtkmm/label.h:46:17: note: forward declaration of ‘class Gtk::Menu’
   46 | class GTKMM_API Menu;
      |   

main.cc

#include <gtkmm.h>
//#include <gtkmm/menu.h>

class AppMenu: public Gtk::Menu
{
    public:
        AppMenu();
};

int main()
{
    printf("Hello world\n");
    return 0;
}

I am compiling using the command

g++ main.cc 'pkg-config --cflags --libs gtkmm-4.0' -I/usr/include/gtkmm-4.0/gtkmm/menu.h

I tried using the header <gtkmm/menu.h> but this is not found for whatever reason, also i tried to use class Gtk::Menu; but this is wrong since the class is already declared in gtkmm header file

misha
  • 31
  • 5
  • 1
    You just *have to* include the header that defines `Menu`. No way around that. A forward declaration `class Menu;` allows you to use a pointer or reference to the class, but not much else. As a base class, its members must be known. – BoP Apr 11 '23 at 08:47
  • @BoP i did try to use `#include ` but the header is not found – misha Apr 11 '23 at 08:53
  • So that is not the correct include path. Either it is missing from the install, or it is somewhere else - at a different path. Up to you to find out. – BoP Apr 11 '23 at 08:56
  • @BoP I did add `-I-I/usr/include/gtkmm-4.0/gtkmm/menu.h` to the compile command but still the same error – misha Apr 11 '23 at 09:52
  • @misha, add only `-I/usr/include/gtkmm-4.0` and retry. – kiner_shah Apr 11 '23 at 10:16
  • `gtkmm-4` doesn't have `menu.h`, you need to go to the giomm library for that. Also, gtkmm classes are not really designed for inheritance. – n. m. could be an AI Apr 11 '23 at 10:23
  • @n.m. i am using pkg-config and it automatically adds giomm but i still get the incomplete type error – misha Apr 11 '23 at 16:07
  • You need to `#include `. – n. m. could be an AI Apr 11 '23 at 17:48

0 Answers0