Is there a particularly good reason to choose to use an elaborated type specifier? For example, in certain circumstances, one is required to use the template
or typename
keywords to disambiguate a dependent template
or type.
But I can't think of any examples where this would occur for something such as an enumeration. Take the following code example:
enum Foo { A, B };
void bar(Foo foo);
void baz(enum Foo foo);
Why might I choose to use the syntax baz()
provides over bar()
(or vice-versa)? Is there any ambiguous case?
There are no reasons to use such specifiers, unless you are dealing with the situation when the name is hidden by name of a different "kind". For example, it is perfectly legal to declare a variable named Foo
after the enum declaration, since, speaking informally, object names and type names live in independent "namespaces" (see 3.3/4 for more formal specification)
enum Foo { A, B };
int Foo;
After the int Foo
declaration, your bar
declaration will become invalid, while the more elaborate baz
declaration will remain valid.
Elaborated type specifiers are required for declaring user-defined types. One use case is to forward declare your types. In the unlikely event that you have a function with the same name as an enum
you have visible in scope you may need to use the elaborated type specifier in the function declaration:
enum A { A_START = 0 };
void A(enum A a) {}
int main() {
enum A a;
A( a );
}
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