链接隐式转换运算符 [英] Chaining implicit conversion operators

查看:126
本文介绍了链接隐式转换运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,我需要隐式转换为几个事情,中间值,例如

I've got a class which I need to implicitly convert to a few things, with intermediate values, e.g.

struct outer {
    struct inner {
        operator T() { return T(); }
    };
    operator inner() { return inner(); }
};

如果我有这种结构,总是

If I have this structure, is it always valid to do, e.g.

void f(T t);
outer o;
f(o);


推荐答案

§13.3.3.1。 2 [over.ics.user] p1


用户定义的转换序列包含初始标准转换(12.3),后跟第二个标准转换序列。

A user-defined conversion sequence consists of an initial standard conversion sequence followed by a user-defined conversion (12.3) followed by a second standard conversion sequence.

注意单数和缺少的单词序列。在隐式转换序列期间,只会考虑一个用户定义的转换。

Notice the singular and the missing of the word "sequence". Only one user-defined conversion will ever be considered during an implicit conversion sequence.

这篇关于链接隐式转换运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆