尝试将类和对象放在头文件中并不断收到此错误,不确定是否因为我没有包含正确的文件或者它的编写错误。 错误在第28行:iItemPrice [iCount]
#include "stdafx.h"
#include <string>
#include <conio.h>
#include <array>
#include <vector>
#include "ItemsClass.h"
#include "A2main.cpp"
#include <iostream>
using namespace std;
ItemsClass::ItemsClass()
{
}
void ItemsClass::enter_items() {
string sItmes[5];
string sChoice;
int iCount;
int iItemPrice;
int iNumOfItems;
do {
cout << "--------- ENTER NEW ITEMS ---------\n\nPlease enter the item Name: ";
cin >> sItems[iCount];
cout << "\nPlease enter the price of: " << sItems[iCount] << "\n";
cin >> iItemPrice[iCount];
cout << "\nWould you like to enter another item? Y/N \n";
cin >> sChoice;
if (sChoice == "Y" || sChoice == "y")
{
++iCount;
++iNumOfItems;
}
} while ((sChoice == "Y" || sChoice == "y") && iNumOfItems < 5);
}
答案 0 :(得分:2)
iItemPrice被声明为int。不是数组/指针。
声明为:
int iItemPrice[5];
答案 1 :(得分:1)
iItemPrice
不是数组。如果要使用int iItemPrice[size]
创建数组,最好使用std::vector<int> iItemPrice