尝试使用自定义类的向量引用已删除的函数vector.erase

时间:2018-05-20 16:44:30

标签: c++ visual-studio

我正在尝试在SDL中实现Gui。将以下函数添加到我的gameWindow对象会给我一个错误。

class gameWindow {
private:
    ...
    std::vector<guiObject> guiObjects;
    ...
public:
    ...
    void deleteGuiObjectbyIndex(unsigned int index)
    {
        guiObjects.erase(guiObjects.begin()+index);
    };
    ...
};

函数中的guiObject如下:

class guiObject {
private:
    SDL_Rect position;
    SDL_Texture* texture;
    gameWindow &gWindow;
    gameState &gState;
    eventHandler &eHandler;
    bool deleteOnClick;
    int id;

public:
    guiObject(int id,bool deleteOnClick, SDL_Rect _position, SDL_Texture* _texture, gameWindow & _gWindow, gameState & _gState, eventHandler & _eHandler) :
    id(id),deleteOnClick(deleteOnClick),gWindow(_gWindow), gState(_gState), position(_position), texture(_texture),eHandler(_eHandler)
    {};
    SDL_Texture* getTexture();
    SDL_Rect* getPosition();
    void (guiObject::*onClick)();
    void startPlay();
    bool delOnClick(){return deleteOnClick;};
    int getID(){return id;};
};

我得到的错误是:

Error   C2280   'guiObject &guiObject::operator =(const guiObject &)': attempting to reference a deleted function

0 个答案:

没有答案