简体   繁体   English

转换function的显式调用和隐式调用有什么区别?

[英]What's the difference between an explicit call and an implicit call of the conversion function?

Consider this example:考虑这个例子:

struct A{
    template<class T>
    operator T();  // #1
};
struct B:A{
    template<class U>
    operator U&&();  // #2
};
int main(){
  B  b;
  int a = b;  // #3
  b.operator int();  // #4
}

According to [class.member.lookup] p7根据 [class.member.lookup] p7

If N is a non-dependent conversion-function-id, conversion function templates that are members of T are considered.如果 N 是非依赖转换函数 ID,则考虑作为 T 成员的转换 function 模板。 For each such template F, the lookup set S(t,T) is constructed, considering a function template declaration to have the name t only if it corresponds to a declaration of F ([basic.scope.scope]).对于每个这样的模板 F,构造查找集S(t,T) ,考虑 function 模板声明只有当它对应于 F 的声明([basic.scope.scope])时才具有名称t The members of the declaration set of each such lookup set, which shall not be an invalid set, are included in the result.结果中包括每个此类查找集的声明集的成员,这些成员不应是无效集。

#1 and #2 are both included in the lookup result regardless of what the conversion-function-id s are in #3 and #4 . #1#2都包含在查找结果中,而不管#3#4中的conversion-function-id是什么。 The diagnosis for #3 is what we expect, in other words, both #1 and #2 are candidates and they are indistinguishable. #3诊断是我们所期望的,换句话说, #1#2都是候选者,并且无法区分。

However, it seems that implementations only consider #2 as the unique candidate when processing #4 .但是,在处理#4时,实现似乎只将#2视为唯一候选者。 As said above, the candidate set should be the same for either #3 or #4 .如上所述, #3#4的候选集应该相同。 Do I omit some other rules that cause the difference?我是否忽略了其他一些导致差异的规则? Or, Is it a bug in implementations?或者,它是实现中的错误吗?

Implementations just haven't caught up to the new(ly clarified) rules, which had to be largely invented in 2020 since no published standard version has ever described lookup for conversion function templates in any sensible way.实施只是没有跟上新的(已澄清的)规则,这些规则必须在 2020 年大量发明,因为没有发布的标准版本以任何合理的方式描述转换 function 模板的查找。

暂无
暂无

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

相关问题 C ++中显式和隐式赋值之间的区别是什么 - What's the difference between explicit and implicit assignment in C++ 对转换 function 的隐式调用是否归类为显式调用(prvalue、xvalue、lvalue 等)? - Is an implicit call to a conversion function categorised as an explicit call (prvalue, xvalue, lvalue, etc.)? 在函数调用中创建的对象与传入的对象之间有什么区别 - What's the difference between an object created in function call and object passed in 在这种情况下,通过构造函数或显式函数更好的隐式转换是什么? - What is better implicit conversion through constructor or explicit function in this case? 显式operator = call和=运算符之间可以有区别吗? - Can there be a difference between explicit operator= call and = operator? 仿函数的调用和函数调用之间的详细区别? - Detailed difference between functor's call and function call? 使用带或不带函数调用运算符 () 的 mt19937_64 实例有什么区别? - What's the difference between using an mt19937_64 instance with or without the function call operator ()? 模板调用有什么区别? - What is the difference between template call? 运算符()的“显式”和“隐式”调用之间的区别 - Difference between “explicit” and “implicit” invocation of operator () 来自新重载的调用构造函数和直接调用的构造函数之间有什么区别? - What's the difference between call constructor from new overload and directly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM