1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // OK { typedef struct Y {float a;} Y; int Y = 2; } // OK { enum RGBColor {Red, Green, Blue}; // user defined type RGBColor RGBColor myColor = Red; // a RGBColor int RGBColor = 7; // should produce an error } // Not OK { enum RGBColor {Red, Green, Blue}; // user defined type RGBColor int RGBColor = 7; // should produce an error RGBColor myColor = Red; // a RGBColor; error: syntax error : missing ';' before identifier 'myColor' } |
Stroustrup called this a "C compatibility hack."
In C, the struct tag is not a "real" type. A common practice is
1 | struct s{/*...*/} s; |
In C++, the struct tag defines a type and the typedef just adds another type name;
thus the "pollution".
- tim