我的错误似乎是这个错误的衍生物:
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;
}
...
问题是什么?我该如何解决? 非常感谢任何帮助,谢谢。
答案 0 :(得分:3)
看起来hashbang
之前是未知的:
Item
如果您在Item itemArray[MAX_ITEMS]; //error seems to occur here
类定义之前添加:#include "Item.h"
,或者切换:
Order
为:
#include "Order.h"
#include "Item.h"