简体   繁体   English

我想看一个例子,其中在整个postfix-expression的上下文中查找conversion-type-id

[英]I'd like to see one example where the conversion-type-id is looked up in the context of the entire postfix-expression

In [basic.lookup.classref]/7 (C++14) we have (emphasis is mine): 在[basic.lookup.classref] / 7(C ++ 14)中我们有(重点是我的):

If the id-expression is a conversion-function-id , its conversion-type-id is first looked up in the class of the object expression and the name, if found, is used. 如果id-expressionconversion-function-id ,则首先在对象表达式的类中查找其conversion-type-id ,并使用名称(如果找到)。 Otherwise it is looked up in the context of the entire postfix-expression . 否则,它将在整个postfix-expression的上下文中查找。 In each of these lookups, only names that denote types or templates whose specializations are types are considered. 在每个查找中,仅考虑表示其特化类型的类型或模板的名称。

I don't understand the need for the Otherwise above. 我不明白上面的其他需要。 Therefore, I'd like to see an example, where the conversion-type-id is looked up in the context of the entire postfix-expression. 因此,我想看一个示例,其中在整个postfix-expression的上下文中查找conversion-type-id

Something like this : 像这样的东西:

struct C {
    operator int() { return 42; }
};

typedef int X;

int main() {
  C c;
  c.operator X();  // calls c.operator int();
}

Clearly, the name X is not found in class C , but is found in the context of the expression where it's used. 显然,在类C找不到名称X ,但是在使用它的表达式的上下文中找到它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 后缀表达评估 - Postfix-expression evaluation 如何显式调用转换类型 ID 包含占位符说明符的转换 function - How to explicitly call a conversion function whose conversion-type-id contains a placeholder specifier 多个后缀表达式(下标)评估是否会导致 UB - Do the multiple postfix-expression(subscripting) evaluations result in UB 为什么用C ++语法static_assert是声明而不是postfix-expression? - Why static_assert is a declaration instead of a postfix-expression in C++ syntax? 我想在嵌套名称说明符中看到一个函数名称被忽略的例子 - I'd like to see an example of a function name being ignored in a nested-name-specifier 为什么int(a)是一个表达式而int(unsigned(a))在下面的例子中是一个type-id? - Why is int(a) an expression and int(unsigned(a)) a type-id in the example below? 我想在C ++中看到一个hash_map示例 - I would like to see a hash_map example in C++ DirectX C++ 问题:D3D11_DEPTH_STENCIL_DESC 没有我正在学习的成员。 我查了这个 我没有显示的内容 - DirectX C++ Question: D3D11_DEPTH_STENCIL_DESC does not have the members that I am being taught. I looked this up I don't have what is shown 我已经编写了此程序以将后缀转换为后缀 - I have written this program for infix to postfix conversion 如何使用§8.3.1和§8.3.4推断出像'[]'这样的后缀声明符运算符比使用'*'这样的前缀绑定? - How can I deduce that a postfix declarator operator like '[]' binds tigther than a prefix one like '*' using §8.3.1 and §8.3.4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM