在[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. Otherwise it is looked up
in the context of the entire postfix-expression. In each of these
lookups, only names that denote types or templates whose
specializations are types are considered.
我不明白上面的其他需要.因此,我想看一个示例,其中在整个postfix-expression的上下文中查找conversion-type-id.
解决方法:
东西like this:
struct C {
operator int() { return 42; }
};
typedef int X;
int main() {
C c;
c.operator X(); // calls c.operator int();
}
显然,在类C中找不到名称X,但是在使用它的表达式的上下文中找到它.