C++0x rvalue references and temporaries

后端 未结 6 2016
独厮守ぢ
独厮守ぢ 2021-02-01 23:37

(I asked a variation of this question on comp.std.c++ but didn\'t get an answer.)

Why does the call to f(arg) in this code call the const ref overload of

6条回答
  •  旧时难觅i
    2021-02-02 00:03

    I don't know if that has changed in the latest versions of the standard, but it used to say something like "if in doubt, don't use the rvalue reference". Probably for compatibility reasons.

    If you want the move semantics, use f(std::move(arg)), that works with both compilers.

提交回复
热议问题