user613326
user613326

Reputation: 2180

error use of enum without previous declaration?

I'm learning C++ from a book and the following example doesn't work in codeblocks. My compiler gives an error:

use of enum 'Days' without previous declaration

Can someone enlight me here?

#include <iostream>
using namespace std;

int main() // main routine
{
    int a;
    enum Days (zo,ma,di,wo,do,vr,za); // <error here> : use of enum 'Days' without previous declaration
    Days today;
    today = ma;
    if (today == zo || today == za)
        cout << "weekend \n"
    else
        cout << "ohno workday \n";
    return 0;
}

Upvotes: 5

Views: 22531

Answers (1)

Qaz
Qaz

Reputation: 61910

You're using enum incorrectly. Your parentheses should be braces:

enum Days {zo,ma,di,wo,do,vr,za};

Now zo will be equal to 0, since you didn't explicitly define a value, and each thereafter will be one more than the last.

Also notice (easily, due to syntax highlighting) that do conflicts with the do keyword reserved for do...while statements.

Upvotes: 14

Related Questions