本文介绍了在未限定名称查找期间找到的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下简单示例:

#include <iostream>

int a=5;//1
extern int a;//2

int main(){ cout << a; }

标准说(3.4 / 1节):

The standard said that (sec. 3.4/1):

。3.4.1 / 1):

and (sec. 3.4.1/1):

问题:我的案例中会找到什么声明(1或2),为什么?

Question: What declaration (1 or 2) will be found in my case and why?

推荐答案

该子句声明名称查找停止,当它命中 int a = 5;

That clause says that name lookup stops when it hits int a=5;

在全局命名空间中只有一个名称, a 。它不含糊,因为只有一个 a ,如果有多个声明 a 没有关系。两个声明,一个名字。 (模糊情况只能发生在类成员名称查找,这在该部分中有更充分的描述)。

There is only one name here, a in the global namespace. It's not ambiguous because there is only one a, it doesn't matter if there are multiple declarations of a. Two declarations, one name. (The "ambiguous" case can only occur for class member name lookup, which is more fully described in that section).

我从你的措辞期望有某种不同的行为取决于1或2是否满足这条款;但没有。

I get the sense from your wording that you are expecting there to be some sort of different behaviour depending on whether 1 or 2 satisfies this clause; but there isn't.

这篇关于在未限定名称查找期间找到的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:28