expected unqualified-id before '{' token

I know that this error is usually due to syntax errors, but I can not find anything wrong with this code. Can someone help me point this out? Here are the errors I get:

deli.cc:10:7: error: expected unqualified identifier before '[token int [] myCashierNums; ^ deli.cc:11:7: error: expected unqualified identifier before '[token int [] myOrderNums; ^

Here's a program compiled with 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[]) { } 
+8
c ++ g ++
source share
2 answers

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

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

Note that arrays in C ++ must have size at compile time. In the above example, this is 1000.

+21
source share

changes:

 int myMaxOrders; int* myCashierNums; int* myOrderNums; 

add:

 ~SandwichBoard() { if (myMaxOrders) { delete [] myCashierNums; delete [] myOrderNums; } } 
+2
source share

All Articles