Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: expected unqualified-id before ‘for’

Tags:

The following code returns this: error: expected unqualified-id before ‘for’

I can't find what is causing the error. Thanks for the help!

#include<iostream>

using namespace std;

const int num_months = 12;

struct month {
    string name;
    int n_days;
};

month *months = new month [num_months];

string m[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 
              "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int n[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

for (int i=0; i<num_months; i++) {
    // will initialize the months
}

int main() {
    // will print name[i]: days[i]
    return 0;
}
like image 495
Morlock Avatar asked Feb 19 '10 03:02

Morlock


People also ask

How do you fix expected unqualified ID before token?

– Adjust the Curly Braces To Fix the Expected Unqualified Id Error. You should match the opening and closing curly braces in your code to ensure the right quantity of brackets. The code should not have an extra or a missing curly bracket.

What is expected unqualified ID before numeric constant?

expected unqualified-id before numeric constantCython is a tool to wrap C/C++ code so that it can interface with a Python interpreter. Cython generates the wrapping code and sends it to GCC.


2 Answers

Your for loop is outside a function body.

like image 84
missingfaktor Avatar answered Sep 27 '22 22:09

missingfaktor


Ok just to make this answer clear (since I made the rookie mistake too).

the for loop was outside int main() (or any other function) along with everything else since main() sits by itself empty at the bottom of the code.

Sorry more than needed to be said for some but since this issue is more directed to newbies a more elaborate explanation is needed.

like image 38
Anthony Flores Avatar answered Sep 27 '22 22:09

Anthony Flores