I know that this will seem a very basic question, but actually it is not something obvious because of the use of pointers, scopes and GTK especific types of variables and others. I really was not able to find an answer.
I have got to divide the GUI related part of a Gtkmm program into functions, but something seems to be wrong.
To make it clear, here is an example, There is the WORKING code in CODE1.cpp, and it must be divided into something similar to CODE2.cpp (not yet working).
The first one is a window containing only a label, the second is the same, but the label is created inside a function.
Where is the error? What is missing? Any tip or help would be appreciated.
Codes mentioned are the following:
CODE1.cpp:
#include <gtkmm.h>
int main (int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "Ejemplo");
Gtk::Window ventana;
Gtk::Label labela;
labela.set_text("perrito");
ventana.add (labela);
ventana.show_all ();
return app->run(ventana);
}
CODE2.cpp:
#include <gtkmm.h>
Gtk::Label etiqueta (string x)
{
Gtk::Label labela;
labela.set_text(x);
return ( labela );
}
int main (int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "Ejemplo");
Gtk::Window ventana;
etiqueta("perrito");
ventana.add (labela);
ventana.show_all ();
return app->run(ventana);
}