When to use an elaborated type specifier

前端 未结 4 1907
忘掉有多难
忘掉有多难 2020-12-19 04:24

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

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 05:08

    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.

提交回复
热议问题