简体   繁体   English

继承的构造函数-定义可移植的固定大小类型(C ++)

[英]inherited constructor - define portable fixed-size types (C++)

I've a base class with it's constructor, and an inherited class, which has it's own constructor, it does the same thing, but also adds some extra instructions. 我有一个带有构造函数的基类,还有一个继承的类,它具有自己的构造函数,它执行相同的操作,但是还添加了一些额外的指令。

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();
};

The problem is that when I try to initialize base class constructor within inherited class constructor by doing this: 问题是当我尝试通过执行以下操作在继承的类构造函数中初始化基类构造函数时:

IButton::IButton(sf::RenderWindow & rw, sf::Image & teximg, 
                 int x, int y, int width, int icon) 
    : i_base(sf::RenderWindow & rw)
{
    ... //do some things
}

I won't compile because my parser says that sf::RenderWindow is not allowed type, and it seems that it'll only accept fixed-size types. 我不会编译,因为我的解析器说sf :: RenderWindow是不允许的类型,而且似乎只接受固定大小的类型。 So i've changed declaration of i_base constructor to have an int as argument, and the error is gone, but of course it doesn't make any sense in my code. 因此,我已将i_base构造函数的声明更改为具有int作为参数,并且错误消失了,但是在我的代码中它当然没有任何意义。 Is there any way to initialize base constructor with non-fixed-size type? 有什么方法可以使用非固定大小类型初始化基本构造函数? I've tried with pointer, but it doesn't seem to solve anything. 我已经尝试过使用指针,但是似乎没有解决任何问题。

Should be just 应该只是

IButton::IButton(sf::RenderWindow & rw, sf::Image & teximg,
int x, int y, int width, int icon) : i_base(rw)
{
    ... //do some things
}

that means send rw to i_base constructor. 这意味着将rw发送到i_base构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM