vocter容器在使用algorithm的find以及find_if中出现的无法访问private成员变量问题
vector<Bus>bus
class Bus {
private:
int id, nameId, bI, eI;
int number;
public:
Bus();
Bus(const Bus &b);
Bus(int id, int nameId, int bI, int eI);
//重载等于号
bool operator==(const Bus& b);
//重载小括号
bool operator()(const Bus& b);
};
如果这样写,会报错,提示vector无法访问Bus的私有变量,但是我调换一下位置(别问我为什么换)
class Bus {
private:
int id, nameId, bI, eI;
int number;
public:
//重载等于号
bool operator==(const Bus& b);
//重载小括号
bool operator()(const Bus& b);
Bus();
Bus(const Bus &b);
Bus(int id, int nameId, int bI, int eI);
};
vector<Bus> bus;
错误就消失了,不明所以,记录一下。