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;
}
}
}
}
}
我有一个类型为spaces的数据类型的宇宙飞船的2D矢量。 我想添加项目对象到第一个太空船,但它给了我一个错误,说类太空船项目没有一个名为push_back的成员2d向量说类没有名为push_back的成员
这是这条线,我没有看到它有什么问题。
m_itemShips[i].push_back(m_items[itemCount]);
帮助表示赞赏。
编辑:如果你打算让我失望,至少给我一个理由。我只是在问一个问题。
'm_itemShips [i]'看上去是'Spaceship- ',而不是'std :: vector'。 'Spaceship'可能有也可能没有'push_back'方法。没有[mcve]或猜测就不能说更多。关闭主题,请使用[成员初始化程序列表](http://en.cppreference.com/w/cpp/language/initializer_list)。 –
user4581301
飞船是一个模板类。它没有push_back方法,但ManageSupply类创建了一个向量类型spaceship,所以它应该有权访问push_back。我不确定 –
“所以它应该有权访问push_back”什么push_back?你说没有一个,那是你的问题。 – mascoj