冲突声明的C ++标准定义 [英] C++ standard definition of conflicting declarations

查看:196
本文介绍了冲突声明的C ++标准定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准在哪里定义冲突声明?

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;

这将是冲突声明的示例.

推荐答案

根据 [dcl.type] cv限定符 const是该类型的一部分,因此const int x;int x;构成了变量x.

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.

然后我们到达 [over]/1 ,其中指出:

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.

这篇关于冲突声明的C ++标准定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆