加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 限定名称的重载分辨率

发布时间:2020-12-16 07:24:02 所属栏目:百科 来源:网络整理
导读:考虑这个函数调用: foo::bar(); 11.3.1.1.1,第3段[over.call.func](N4778)涵盖了这种情况: In unqualified function calls,the name is not qualified by an - or . operator and has the more general form of a primary-expression . The name is looked
考虑这个函数调用:

foo::bar();

11.3.1.1.1,第3段[over.call.func](N4778)涵盖了这种情况:

In unqualified function calls,the name is not qualified by an -> or . operator and has the more general form of a primary-expression. The name is looked up in the context of the function call following the normal rules for name lookup in function calls…

在这里,foo :: bar是一个不合格的名称,在某种意义上它不符合 – >或..所以本段适用.现在,在第2节[basic.lookup]中解释了“在上下文中查找”这一短语的含义:

A name “looked up in the context of an expression” is looked up as an unqualified name in the scope where the expression is found.

但是,foo :: bar是名称查找领域中的限定名称.换句话说,段落的这种组合基本上说,通过非限定名称查找规则查找限定名称foo :: bar.但是,我不认为不合格的名称查找能够递归地进入更窄的范围,即foo到bar.这是一个缺陷吗?

解决方法

不,我不认为这是一个缺陷.它说

The name is looked up in the context of the function call following the normal rules for name lookup in function calls […]

从我突出显示的部分可以看出,标准指定了如何查找名称:通过名称查找.

名称查找涉及非限定,限定和依赖于参数的查找,因此您的名称确实由限定名称查找规则解析.

“在expr的上下文中查找”规则在此处不适用,因为它指定了使用的规则.只有当它不是时才会发挥作用.例如,在[class.qual]p1:

the names in a template-argument of a template-id are looked up in the context in which the entire postfix-expression occurs.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读