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;
}
You’re using
enumincorrectly. Your parentheses should be braces:Now
zowill 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
doconflicts with thedokeyword reserved fordo...whilestatements.