开发者

What does `class HelloWorld : public Gtk::Window` mean?

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

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


It means that HelloWorld is derived from Gtk::Window, so it inherits its behaviour.

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.

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.


class HelloWorld : public Gtk::Window

This means the class HelloWorld is publically derived from class Window defined inside Gtk namespace. Gtk::Window is the fully qualified name of that class.


I just want to point out that you should either be using the 3.0 branch of gtkmm or you should use the stable branch of the tutorial.link text

The 3.0 branch of gtkmm is still under development, and you should expect a few "surprises" now and then.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜