调用 const 成员函数
我调用了一个对象的 const 成员函数。
在之前设置大小后,我在 MainWindow 上创建了一个名为 get_size() 的对象。
调用基类 Gtk::Window 的 get_size() 方法。
它给出错误:“Gtk::Window”不是“MainWindow”的可访问基础。
MainWindow 是从 Gtk::Window 类继承的,
class MainWindow: Gtk::Window
{
};
这可能是什么原因。
i have called const member function of an object.
I created an object on MainWindow, den called get_size() after setting size previously.
calling get_size() method of base class Gtk::Window.
It gives error: ‘Gtk::Window’ is not an accessible base of ‘MainWindow’.
MainWindow is inherited from Gtk::Window class
class MainWindow: Gtk::Window
{
};
What could be the reason for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认情况下,类的继承是
private
。您需要公开地从Gtk::Window
派生:Inhertance is
private
by default for classes. You need to derive fromGtk::Window
publicly:大概应该是:
should probably be:
如果您使用
private
单词继承(当您没有为class
指定任何单词时,这就是您继承的方式)来自Gtk::Window
在MainWindow
中变为私有(即使它在Gtk::Window
中声明为public
或protected
)。如果您使用
protected
字进行继承,则基类中的每个public
方法都会成为继承类中的protected
方法。private
方法保持原样。public
继承不会改变任何东西。它是使用 struct 关键字声明的类的默认继承。您似乎忘记在类声明中使用
public
。If you inherit with
private
word (and that's how you inherit when you don't specify any word forclass
) every method fromGtk::Window
become private inMainWindow
(even if it's declared aspublic
orprotected
inGtk::Window
).If you inherit with
protected
word everypublic
methods from base class becomeprotected
methods in inherited class.private
methods stay as they are.public
inheritance doesn't change anything. It's default inheritance for class declared withstruct
keyword.It seems you forgot to use
public
in class declaration.