小编Neu*_*ung的帖子

没有匹配的成员函数调用“push_back”错误

//fleet.h 
#include "ship.h"
#include <vector>
#include <iostream>
#ifndef fleet_h
#define fleet_h
using namespace std;

class fleet
{
public:

//Add_ship and remove_ship method
bool add_ship(ship const &s);

private:
vector<ship*> ships;
};

//Add_ship method
bool fleet::add_ship(ship const & s){
    ships.push_back(&s); 
       return true;
}
#endif /* fleet_h */
Run Code Online (Sandbox Code Playgroud)

该程序给了我这个错误,我不确定我做错了什么。船舶对象通过名为 add_ship 的方法添加到舰队中,该方法需要一个指向船舶的指针。

No matching member function for call 'push_back'
Run Code Online (Sandbox Code Playgroud)

c++ vector composition

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

composition ×1

vector ×1