Constructing a value through two implicit constructors?

◇◆丶佛笑我妖孽 提交于 2019-12-01 08:56:00

Your first example requires two user defined conversions to compile — SomeType -> Inner -> Outer. However, at most one user defined conversion can be applied implicitly.

Quoting N3337, §12.3 [class.conv]

1   Type conversions of class objects can be specified by constructors and by conversion functions. These conversions are called user-defined conversions and are used for implicit type conversions (Clause 4), for initialization (8.5), and for explicit type conversions (5.4, 5.2.9).

4   At most one user-defined conversion (constructor or conversion function) is implicitly applied to a single value.


If the goal is to avoid having to mention Inner<SomeType> in the return statement, you can use list initialization.

Outer<Inner<SomeType>> DoSomethingWorks2() {
  SomeType value;
  return {std::move(value)};
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!