mercredi 28 septembre 2016

Pushing derived class to vector of base class in c++

I have the following code:

class Official {
    public:
        explicit Official(int iRow, int iColumn, int iRankHolder, int** aiBoardHolder);
};

class General : public Official {
    public: 
        explicit General(int iRow, int iColumn, int iRankHolder, int** aiBoardHolder) : Official(iRow, iColumn, iRankHolder, aiBoardHolder) {};
};

class Map {
    private:
        std::vector<Official> aoOfficialStack;

    public:
        void generateOfficialObject();
};

void Map::generateOfficialObject() {
    aoOfficialStack.push_back(General(1, 2, 3, aiBoardPosition));
}

Question is why am I getting this error after calling generateOfficalObject()?

Error C2664 'void std::vector>::push_back(const Official &)': cannot convert argument 1 from 'General' to 'Official &&' Project c:\users\user\desktop\project\project\board\board.cpp 12

Thank you very much!

Aucun commentaire:

Enregistrer un commentaire