if( xyz::control::a == 0)
You don't want 'control' in there.
a,b,c and d are constants in the scope of xyz.
control is a type within the scope of xyz.
So you have xyz::a, xyz::b, xyz::c, xyz::d and xyz::control used:
xyz::control my_value = xyz::a;
Also, in this statement:
typedef enum {a=0,b,c,d} control;
in c++ (as opposed to c) you can just write
enum control {a=0,b,c,d};
Think of it like a struct or class ...
struct control { /* Whatever*/ };
gives you the ability to say:
control c;
in your code.
If you look at c code you will often see something more like
struct control c;
because you do not have the implicit type.
class xyz
{
enum {a=0,b,c,d} control;
}
is giving you a member control of class xyz. of type enum.
preceding this with typedef (as you have and want but do not need to) makes control a type in the scope of xyz.
Yes, it is confusing
- it is for me. I would suggest using a reference book just to confirm these points, regarding the precise usage.
It gets pretty in depth.
I might edit this a bit after reading back.
Summary:
Code:
class xyz
{
enum {a=0,b,c,d}; // 1. Gives you xyz::a , xyz::b as CONSTANTS.
enum {a=0,b,c,d} control; // 2. Gives you xyz::control as a MEMBER of xyz
enum control {a=0,b,c,d}; // 3. Gives you xyz::control as a TYPE
// and xyz::a etc. as CONSTANTS
typedef enum {a=0,b,c,d} control; // Same as 3.
};
I think