c++ - 为什么我收到语法错误:缺少';' 前 '*'
问题描述
在类声明中,我在两行上收到此错误。当我尝试声明一段成员数据时,我得到了它,这是一个指向具有全局常量 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 { }
推荐阅读
- javascript - 无法弄清楚如何使用 React - Mic 播放我的唱片
- c++ - 让 llvm/clang(来自 brew)在 OSX 上工作
- bash - fcntl(), F_GETFD 在 UNIX 中的含义
- c# - 在没有 .dbml 设置的情况下,如何在 Visual Studio 中通过 linq 调用存储过程?
- php - 准备好的语句返回的 PHP MySql 选择计数始终为 1
- awk - 如何围绕每个部分的一个特定字母将数据拆分为 5 个字母
- javascript - 在node.js上发出http请求是否正常
- php - Symfony 升级到 Symfony 4.2 后出现“尝试加载类”错误
- php - WordPress 发布下一个和上一个链接
- python - Django queryset : Calculate monthly average