【发布时间】:2015-12-29 13:01:11
【问题描述】:
我有一个带有构造函数的基类和一个继承类,它有自己的构造函数,它做同样的事情,但还添加了一些额外的指令。
class i_base //Base class for any interface objects
{
public:
...//declare some things
i_base(sf::RenderWindow & rw);
virtual ~i_base();
};
class IButton
:public i_base
{
private:
int w, h;
public:
IButton(sf::RenderWindow & rw, sf::Image & teximg,
int x, int y, int width, int icon);
~IButton();
};
问题是当我尝试在继承的类构造函数中初始化基类构造函数时:
IButton::IButton(sf::RenderWindow & rw, sf::Image & teximg,
int x, int y, int width, int icon)
: i_base(sf::RenderWindow & rw)
{
... //do some things
}
我不会编译,因为我的解析器说 sf::RenderWindow 是不允许的类型,而且它似乎只接受固定大小的类型。所以我已经将 i_base 构造函数的声明更改为有一个 int 作为参数,并且错误消失了,但当然它在我的代码中没有任何意义。有没有办法用非固定大小类型初始化基本构造函数?我试过指针,但它似乎没有解决任何问题。
【问题讨论】:
标签: c++ inheritance constructor fixed-size-types