The reason, as indicated in your quote from Straustrup, is historical. In C, you should always specify the name struct with struct ; the name of the structure (for example, the name of unions or enumerations) is called a tag and lives a completely different namespace than other characters. So things like:
struct stat { // ... }; int stat( char const* filename, struct stat* buf );
are completely legal. (This is, in fact, part of Posix).
In C ++, a class name (declared using class , struct or union ), or an enumeration is in the same namespace as everything else, and unlike C, you can write things like:
struct MyClass {}; MyClass variableName;
This will not be legal C. In C, the second line should be:
struct MyClass variableName;
The problem is that C ++ should be able to use interfaces defined in C (for example, the Posix interface, above). Therefore, C ++ defines some special rules that allow this: you can specify a variable or function and the class type has the same name. When you do this, the name of the variable or function takes precedence and hides the class name, with the exception of “specified type specifiers” (ie class , struct , union or enum followed by a character), where non-type names are ignored when searching .
source share