什么是`HelloWorld:public Gtk :: Window'是什么意思? [英] What does `class HelloWorld : public Gtk::Window` mean?
问题描述
我正在关注GtkHello World教程在这里,我遇到了一个类声明我从来没有见过的一行(我只是学习编程几个月了),我想知道是否有人可以给我解释。该行是
I'm following the Gtk "Hello World" tutorial found here, and I've come across a line in a class declaration I've never seen before (I've only been learning to program for a few months now), and I was wondering if someone could please explain it to me. The line is the
class HelloWorld : public Gtk::Window
我知道类HelloWorld
在做什么,但我从来没有见过 public Gtk :: Window
之前。提供完整的头文件以供参考。
I know what class HelloWorld
is doing, but I've never seen the public Gtk::Window
before. The full header file is provided for reference.
#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
#define GTKMM_EXAMPLE_HELLOWORLD_H
#include <gtkmm/button.h>
#include <gtkmm/window.h>
class HelloWorld : public Gtk::Window
{
public:
HelloWorld();
virtual ~HelloWorld();
protected:
//Signal handlers:
void on_button_clicked();
//Member widgets:
Gtk::Button m_button;
};
#endif // GTKMM_EXAMPLE_HELLOWORLD_H
推荐答案
这意味着 HelloWorld
是从 Gtk :: Window
派生的,因此它继承了它的行为。
It means that HelloWorld
is derived from Gtk::Window
, so it inherits its behaviour.
HelloWorld
表示一个Gtk窗口,所以它是很自然的从Gtk的窗口类派生。它的构造函数可能会向窗口添加一个按钮(实际的窗口是由父类构造函数创建的,当创建一个 HelloWorld
的新实例时会自动调用...)和
HelloWorld
represents a Gtk window, so it is just natural to have it derive from the Gtk's window class. It's constructor will probably add a button to the window (the actual window is created by the parent class constructor, which is invoked automatically when a new instance of HelloWorld
is created …) and connect a signal handler (on_button_clicked
) to the window.
您可以调用的所有
的方法通过 HelloWorld
的实例。反过来, HelloWorld
可以覆盖 Gtk :: Window
的虚方法来更改其行为。
You can call all of Gtk::Window
's methods through an instance of HelloWorld
. In turn, HelloWorld
can override virtual methods of Gtk::Window
to change its behaviour.
这篇关于什么是`HelloWorld:public Gtk :: Window'是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!