0
votes

I am trying to create a simple window in GTKMM that contains a box. I've got the window part working, but I can't get my box code to work. I am following along with this tutorial

I think the tutorial is a little bit dated because Anjuta (the IDE I'm using) generated some different code. Here is my code that should add a box:

 #include <gtkmm.h>
#include <iostream>
#include "config.h"
 using namespace Gtk;



  int main (int argc, char *argv[])
  {
Gtk::Main kit(argc, argv);


Gtk::Window *main_win = new Gtk::Window (Gtk::WINDOW_TOPLEVEL);
main_win->set_title ("Image-Viewer");

Gtk::Box *box = Gtk::manage (new Gtk::Box());
box ->set_orientation (ORIENTATION_VERTICAL);
box->set_spacing(6);
*main_win -> add(*box);

if (main_win)
{
    kit.run(*main_win);
}
return 0;
 }

In the code on the tutorial the window is not created in the same way. As you can see below, the window in my code is being created so that it is in the heap, rather than the stack. (or at least I think [I am new to C++]). I know that items in the heap should be used like a pointer, so for the add function I did that, (rather than using the dot notation described in the tutorial). When I run this code, I get an error stating the following:

error:void value not ignored as it out to be

The error is pertaining to the add method being called on the window. Can somone tell me what I'm doing incorrectly? Thanks

1

1 Answers

2
votes

This instruction:

Gtk::Window *main_win = new Gtk::Window (Gtk::WINDOW_TOPLEVEL);

Declares a pointer to Gtk::Window. Later, you do:

*main_win -> add(*box);

This is incorrect, because you basically try to apply operator -> after you already dereferenced the main_win pointer - and the result of this dereferencing is not a pointer itself, but a reference to an object of type Gtk::Window.

To fix the problem, remove the extra dereferencing:

main_win -> add(*box);

NOTE:

I do not know Gtk::Window and its member function add(), but if it is the case that add() accepts a pointer as its argument, then you also shouldn't dereference box.