'['标记之前预期的非限定标识 [英] Expected unqualified-id before '[' token
问题描述
我知道这个错误通常是语法错误,但我似乎无法找到此代码的任何错误。任何人都可以帮我指出吗?这里是我得到的错误:
I know this error is generally for syntax errors, but I can't seem to find anything wrong with this code. Can anyone help me point it out? Here are the errors I'm getting:
deli.cc:10:7:错误:期望'['令牌之前的非限定符号
int [] myCashierNums;
^
deli.cc:11:7:错误:在'['令牌
int [] myOrderNums;
deli.cc:10:7: error: expected unqualified-id before ‘[’ token int [] myCashierNums; ^ deli.cc:11:7: error: expected unqualified-id before ‘[’ token int [] myOrderNums; ^
下面是我在Ubuntu 14.04 64位上使用g ++编译的程序。
Here's the program I compiled using g++ on Ubuntu 14.04 64-bit.
#include <iostream>
#include <stdlib.h>
using namespace std;
class SandwichBoard {
//private:
int myMaxOrders;
int [] myCashierNums;
int [] myOrderNums;
//public:
SandwichBoard (int maxOrders) {
myMaxOrders = maxOrders;
myCashierNums = new int [maxOrders];
myOrderNums = new int [maxOrders];
// All values initialized to -1
for (int i = 0; i < maxOrders; i++){
myCashierNums[i] = -1;
myOrderNums[i] = -1;
}
}
// For debugging purposes
void printMyOrders() {
for (int i = 0; i < maxOrders; i++){
cout << "Cashier " << myCashierNums[i] << ", ";
cout << "Order " << myOrderNums[i] << endl;
}
}
int getMaxOrders () { return myMaxOrders; }
};
void cashier(void *in) {
}
void sandwich_maker(void *in) {
}
int main(int argc, char *argv[]) {
}
推荐答案
这是C ++,不是Java!
声明这样的数组:
This is C++, not Java! Declare arrays like this:
int myCashierNums[1000];
int myOrderNums[1000];
请注意C ++中的数组在编译时必须有一个大小。在上面的例子中,它是1000.
Please note that the arrays in C++ must have a size at compile time. In the above example, it is 1000.
这篇关于'['标记之前预期的非限定标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!