Possible Duplicate:
Is the typedef-name optional in a typedef declaration?
I’m on Visual Studio 2008 and I saw this:
typedef enum testfoo
{
enum1,
enum2,
enum3
};
Normally the C-style way of using typedef this way requires one additional piece (the name):
typedef enum testfoo
{
enum1,
enum2,
enum3
} testfoo_name;
What is the former example doing? Strangely it compiles, but not sure what it’s actually defining.
There is a difference. The second creates an alias for the
enumbut the first doesn’t. Thetypedefin the first example doesn’t actually do anything. This gives me a warning in GCC so I suspect you can take it out.In C, it’s common to
typedefstructs and enums so as to avoid instantiating with the struct or enum name. For instance:To shorten this, a
typedefdoes the trick:This is no longer necessary in C++ so I’m deriving my assumption of his misconception with this concept. Or maybe the author forgot to give it a name…
The same thing occurs when using classes or structs: