0
我的误差似乎衍生物此错误的:C++:错误与用户定义的类型的阵列
error C2146: syntax error : missing ';' before identifier 'itemArray'
没有缺少分号但我也得到在同一行上这样的错误:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我不明白为什么会出现这些错误。
Order.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
Order.cpp
#include "stdafx.h"
#include "Order.h"
#include "Item.h"
#include <iostream>
using namespace std;
...
Item.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
Item.cpp
#include "stdafx.h"
#include "Item.h"
#include <iostream>
#include <string>
Item::Item()
{
static int currentNum = 0;
itemNum = ++currentNum;
}
...
这是什么问题,如何解决? 任何帮助非常感谢,谢谢。
'Order.h'中是否包含'Item.h'?这里不存在。 – Lasoloz
'Order.h'包含'Item.h'吗? – NickLamp
如果你在Order.h中不包含'#include“Item.h”',那么编译器如何知道'Item'是为了处理它而生成的代码?你也会在Item.cpp中遇到类似的问题。 –