C++ standard definition of conflicting declaration

2019-07-13 10:25发布

问题:

Where does the standard define what a conflicting declaration is?

For example, if I have, at namespace scope, the following declarations:

extern const int a;
extern int a;

this would be an example of conflicting declarations.

回答1:

According to [dcl.type], the cv-qualifier const is part of the type, therefore const int x; and int x; constitute different declarations of the variable x.

Then we arrive at [over]/1, which states that:

When two or more different declarations are specified for a single name in the same scope, that name is said to be overloaded. By extension, two declarations in the same scope that declare the same name but with different types are called overloaded declarations. Only function and function template declarations can be overloaded; variable and type declarations cannot be overloaded.