扩展 GtkWindow 的类
我正在尝试学习 C++,但我找不到是否可以通过这种方式扩展类:
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'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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢,
我试图像使用 C++ 一样使用 C 库。
这就是我用 gtkmm 解决的方法:
main.cc
examplewindow.h
examplewindow.cc
还添加了成功完成的命令,至少在 Arch Linux 上:
另一个小指示,我应该使用什么作为动态数组或向量以及哈希图?
thanks,
I was trying to use C libraries as if they were C++.
This is how I solved with gtkmm:
main.cc
examplewindow.h
examplewindow.cc
also add the command to complete successfully, at least on Arch Linux:
another small indication, what i shouldl use as dynamic arrays or vectors and for hashmap?
我建议你看看 gtkmm (http://www.gtkmm.org/< /a>) 如果您想将 GTK+ 与 C++ 结合使用,即无需尝试重新发明轮子并为 GTK+(它是一个 C 库)编写自己的 C++ 接口。
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).