【发布时间】:2018-09-10 01:50:39
【问题描述】:
我有两个班级:Item 和 Box。在Box.h 我有:
class Box {
vector<const Item *> BoxItems;
public:
void AddItem(const Item *i);
}
在Box.cpp:
void Box::AddItem(const Item *i) {
BoxItems.push_back(*i);
}
仅供参考,但在main.cpp:
box.AddItem(&items[0]);
问题:当我编译时,我得到了error: no matching member function for call to 'push_back',它引用了我在Box.h 中创建的向量中的push_back。 我错过了什么?
到目前为止,我已经尝试过:
void Box::AddItem(const Item *i) {
this -> BoxItems.push_back(*i);
Box::BoxItems.push_back(*i);
BoxItems->push_back(*i);
}
但仍然有同样的错误。
【问题讨论】:
-
push_back(i); -
为什么要取消引用指针?