我的错误似乎是这个错误的衍生物:
error C2146: syntax error : missing ';' before identifier 'itemArray'
没有缺少分号,但我在同一行也收到此错误:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我不明白为什么会发生这些错误。
订单.h
#ifndef ORDER_H
#define ORDER_H
const int MAX_ITEMS = 20;
class Order{
private:
int items;
Item itemArray[MAX_ITEMS]; //error seems to occur here
int orderNum;
int guestNum;
double total;
bool isOpen = true;
public:
Order();
~Order();
void AddItem();
void DeleteItem();
void ChangeItem();
void CloseOrder();
void DisplayOrderDetails();
void SetGuestNum();
};
#endif ORDER_H
序.cpp
#include "stdafx.h"
#include "Order.h"
#include "Item.h"
#include <iostream>
using namespace std;
...
项.h
#ifndef ITEM_H
#define ITEM_H
#include "stdafx.h"
#include <string>
using namespace std;
class Item
{
private:
double price = 0;
string name = "";
bool active = false;
int itemNum = 0;
public:
Item();
~Item();
void CreateItem();
void ChangeItemName();
void ChangeItemPrice();
void RemoveItem();
bool GetActive();
int GetItemNum();
string GetName();
double GetPrice();
};
#endif ITEM_H
项目.cpp
#include "stdafx.h"
#include "Item.h"
#include <iostream>
#include <string>
Item::Item()
{
static int currentNum = 0;
itemNum = ++currentNum;
}
...
问题是什么,我该如何解决?非常感谢任何帮助,谢谢。
看起来Item
以前是未知的:
Item itemArray[MAX_ITEMS]; //error seems to occur here
如果在类定义之前添加: #include "Item.h"
Order
,或者切换:
#include "Order.h"
#include "Item.h"
自:
#include "Item.h"
#include "Order.h"