ManageShips::ManageShips(vector< Spaceship <Item> > itemShip,
vector< Spaceship <Person> > personShip,
vector< Item > itemCargo,
vector< Person > personCargo){
m_itemShips = itemShip;
m_personShips = personShip;
m_items = itemCargo;
m_person = personCargo;
}
void ManageShips::LoadItemShip(){
int numberItemShips = m_itemShips.size();
int numberOfItems = m_items.size();
int itemCount = 0;
for (int i = 0 ; i < numberItemShips ; i++){
int shipFull = 0;
double shipWeight = 0;
while ( shipFull == 0){
while (itemCount < numberOfItems){
if ((m_items[itemCount].GetWeight() + shipWeight ) > m_itemShips[i].GetCapacity()){
shipFull = 1;
}
else {
m_itemShips[i].push_back(m_items[itemCount]);
shipWeight = m_items[itemCount].GetWeight() + shipWeight;
itemCount = itemCount + 1;
}
}
}
}
}
I have a 2d vector of type spaceships which holds data of type items. I am trying to add item objects into the first spaceship but it gives me an error saying class spaceship item does not have a member named push_back
it's this line and I dont see what's wrong with it.
m_itemShips[i].push_back(m_items[itemCount]);
help is appreciated.
Edit: if youre gonna downvote me atleast give me a reason please. I am just asking a question.
m_itemShipsis a (presumably) astd::vector< Spaceship <Item> >andm_itemsis astd::vector< Item >. (and you have given no information about whatSpaceShiporItemare).This means that
m_itemShips[i].push_back(m_items[itemCount])requiresSpaceShip<Item>to have a member function namedpush_back()that can accept anItem.If
SpaceShip<Item>does not have such apush_back()member function, that explains your error message.Importantly,
SpaceShip<Item>does not magically acquire a method namedpush_back()even if it has a data member of typestd::vector<Item>. If you want such a member function, you have to define it.