开发者

class extending GtkWindow

i'm trying to learn c++, but i can not find if it's possible to extend a class in this way:

main.cc

#include "mWindow.h"
using namespace std;
int main( int argc, char* argv[] ) {
    gtk_init( &argc, &argv );
    mWindow win = mWindow();
    gtk_main();
    return 0;
}

mWindow.cc

#include "mWindow.h"
mWindow::mWindow() {
    gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (this, "my window");
    开发者_运维技巧gtk_widget_show_all (GTK_WIDGET(this));
}

mWindow.h

#ifndef MWINDOW_H_INCLUDED
#define MWINDOW_H_INCLUDED
#include <gtk/gtk.h>
using namespace std;
class mWindow : public GtkWindow {
    public:
        mWindow();
};
#endif


I suggest you take a look at gtkmm (http://www.gtkmm.org/) if you want to use GTK+ in conjunction with C++, i.e. there is no need to try to reinvent the wheel and write your own C++ interface for GTK+ (which is a C library).


thanks, I was trying to use C libraries as if they were C++. This is how I solved with gtkmm: main.cc

#include <gtkmm/main.h>
#include "examplewindow.h"

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);
  ExampleWindow window;
  Gtk::Main::run(window);
  return 0;
}

examplewindow.h

#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm-2.4/gtkmm.h>

class ExampleWindow : public Gtk::Window {
    public:
        ExampleWindow();
};

#endif //GTKMM_EXAMPLEWINDOW_H

examplewindow.cc

#include "examplewindow.h"

ExampleWindow::ExampleWindow() {
    set_title("Gtk::TextView example");
    set_border_width(5);
    set_default_size(400, 200);
    show_all_children();
}

also add the command to complete successfully, at least on Arch Linux:

g++ $(pkg-config --cflags --libs gtkmm-2.4) main.cc examplewindow.cc examplewindow.h -o executable

another small indication, what i shouldl use as dynamic arrays or vectors and for hashmap?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜