简体   繁体   中英

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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