Why const for implicit conversion?

前端 未结 2 1884
谎友^
谎友^ 2020-12-15 09:28

After extensive reading of ISO/IEC 14882, Programming language – C++ I\'m still unsure why const is needed for implicit conversion to a user-defined type with a

2条回答
  •  隐瞒了意图╮
    2020-12-15 09:55

    Per section 5.2.2 paragraph 5, when an argument to a function is of const reference type, a temporary variable is automatically introduced if needed. In your example, the rvalue result of X(99) has to be put into a temporary variable so that that variable can be passed by const reference to implicit_conversion_func.

提交回复
热议问题