Apr 18, 2014 at 1:35pm UTC
Well:
1 2 3 4
enum MyEnum{a, b, c, d, e};
int main()
{
std::cout << a;
just works fine, it prints 0;
Is it also possible to declare an enumeration globally and just use it like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
enum lewd{PLUS, MINUS};
struct lawd
{
int a;
int &operator ()(lewd lw, int value)
{
if (lw == PLUS)
{
a+=value;
}
}
};
int main(int argc, char * argv[])
{
lawd lel;
lel.a = 1;
lel(PLUS, 2);
cout << lel.a << endl;
}
Last edited on Apr 18, 2014 at 2:06pm UTC
Apr 18, 2014 at 2:41pm UTC
I mean
1 2 3 4 5 6 7 8 9 10 11 12
enum MyEnum{a, b, c, d}
struct MyStruct
{
int a;
int &operator ()(MyEnum)
};
int main()
{
MyStruct mystruct;
MyStruct(b); //This shouldn't work right? Beacuse i've never declared a variabile of type MyEnum like MyEnum myenum = b;
}
Last edited on Apr 18, 2014 at 2:41pm UTC
Apr 18, 2014 at 2:56pm UTC
I may be wrong, but I think what that line is doing is creating an instance of type MyStruct named b.