samedi 28 novembre 2020

Can't find a way to delete elements of a class object vector [duplicate]

I am using a vector of class types for my school project. The vector is called knightVec and I can use some vector functions no prob, for example knightVec.size() or knightVec.push_back(...) but when I try to use knightVec.erase(1) (or any position) it throws this error:

no instance of overloaded function "std::__1::vector<_Tp, _Allocator>::erase [with _Tp=Knight, _Allocator=std::__1::allocator<Knight>]" matches the argument list -- argument types are: (int) -- object type is: std::__1::vector<Knight, std::__1::allocator<Knight>>C/C++(304)

I can use member functions of the class, like in knightVec[1].getHealth() and those don't give errors.

Aucun commentaire:

Enregistrer un commentaire