Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error use of enum without previous declaration?

Tags:

c++

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;
}
like image 631
user613326 Avatar asked Jun 04 '12 20:06

user613326


1 Answers

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.

like image 55
chris Avatar answered Sep 24 '22 20:09

chris