I saw the following in the header file
typedef enum Test__tag {
foo,
bar
} Test;
I am wondering why using typedef; I can just use
enum Test{
foo,
bar
};
is that right?
It's for C users. Basically when you go the typedef
way, in C you can say
Test myTest;
whereas when you just used enum Test
, you'd have to declare a variable like this:
enum Test myTest;
It's not needed if only C++ is used though. So it might also just be written by a C programmer who is used to this style.
Yes, in C++ you declare x
without the typdef just by writing
enum Test{
foo,
bar
};
Test x;
However if you were to try the same thing in C you would need to declare x
as
enum Test x;
or use the typedef.
So the the typedef is probably a habit left over from C (unless the header file is in fact C).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With