在类声明中,我在两行上收到此错误。当我尝试声明一个成员数据时,就得到了它,这是一个指向具有全局常量int数组大小的对象的指针数组。第二次出现错误是当我声明一个成员函数时,该成员函数返回一个指向与数组相同类型的对象的指针。这两个都是班上的私人成员。
我知道我并没有错过数组的类声明和函数返回值的结尾分号。我试过将语法中的星号移动到靠近变量名,靠近变量类型以及两者之间的位置。
class InventorySystem {
public:
InventorySystem();
InventorySystem(int store_id, string store_name);
~InventorySystem();
void set_store_name(string store_name);
void set_store_id(int store_id);
void set_item_count(int item_count);
string get_store_name(void) const;
int get_store_id(void) const;
int get_item_count(void) const;
void BuildInventory(void);
void ShowInventory(void) const;
void UpdateInventory(void);
void Terminate(void) const;
private:
string store_name_;
int store_id_;
InventoryItem *p_item_list_[g_kMaxArray]; // THIS LINE
int item_count_;
InventoryItem* FindInventoryItem(int item_id) const; // THIS LINE
};
class InventoryItem {
public:
InventoryItem();
InventoryItem(bool restocking);
virtual ~InventoryItem();
void set_restocking(bool restocking);
bool get_restocking(void) const;
int get_item_id(void) const;
void Display(void) const;
protected:
int item_id_;
bool restocking_;
};
我收到很多错误消息,但是似乎所有错误消息都可以追溯到这两个。我无法编译我的代码,也不知道为什么。如果可以提供更多相关信息,请告诉我。谢谢。
您尚未声明课程InventoryItem
。只需移动:
class InventoryItem { }
以上:
class InventorySystem { }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句