c++ - 为什么我收到语法错误 : missing ';' before '*'

标签 c++

在类声明中,我在两行中收到此错误。当我尝试声明一段成员数据时,我得到了它,这是一个指向数组大小为全局常量 int 的对象的指针数组。我第二次收到错误是在我声明一个成员函数时,该函数返回一个指向与数组相同类型的对象的指针。这两个都是类(class)的私有(private)成员。

我知道我没有遗漏数组类声明和函数返回值的结束分号。我尝试将语法中的星号移动到靠近变量名、靠近变量类型或介于两者之间。

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 { }

关于c++ - 为什么我收到语法错误 : missing ';' before '*' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58576095/

相关文章:

c++ - 如何将静态逻辑重构为实现由 C++ 中的参数触发的回调函数的泛型类

c++ - 在 [] 运算符的情况下,为 unordered_map 中的元素设置默认构造函数

c++ struct没有命名类型

C++ OpenMP 每个线程从私有(private)结构对象打印

C++ 我应该用什么代替#define

c++ - Visual Studio 应用程序依赖

c++ - 有没有办法使用 C++/Boost 或使用其他库从 xml 标记中删除 namespace

c++ - 使用分而治之的二维矩阵中的最大和矩形

c++ - 二维数组,无法成功填充数据。

c++ - 具有原子索引的环形缓冲区