Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected unqualified-id before '[' token

Tags:

c++

g++

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: error: expected unqualified-id before ‘[’ token int [] myCashierNums; ^ deli.cc:11:7: error: expected unqualified-id before ‘[’ token int [] myOrderNums; ^

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[]) {

}
like image 550
weskpga Avatar asked Feb 13 '15 04:02

weskpga


People also ask

What does expected unqualified ID before token mean?

The expected unqualified id error shows up due to mistakes in the syntax. As there can be various situations for syntax errors, you'll need to carefully check your code to correct them.

What is an expected identifier in C?

In C, an identifier is expected in the following situations: in a list of parameters in an old-style function header. after the reserved words struct or union when the braces are not present, and. as the name of a member in a structure or union (except for bit fields of width 0).


1 Answers

This is C++, not Java! Declare arrays like this:

int myCashierNums[1000];
int myOrderNums[1000];

Please note that the arrays in C++ must have a size at compile time. In the above example, it is 1000.

like image 173
CinCout Avatar answered Oct 11 '22 18:10

CinCout