LoginSignup
0
0

More than 1 year has passed since last update.

warning C4239 : conversion from 'A' to 'A &' の警告

Posted at
#include <utility>

struct A {};
void fn(A&);

void f()
{
  fn(std::move(A()));
}

上記のようなコードを書いたところ、以下の警告が出た。(コンパイラは VS2012)

warning C4239: nonstandard extension used : 'initializing' : conversion from 'A' to 'A &'
          A non-const reference may only be bound to an lvalue

C4239 は、以下。(2023/4/18 現在)

理由は引数の型が non-const reference であるのに、std::move で rvalue を渡そうとしているため。
rvalue を渡しているのだから関数の引数の型を A&& にしてやるのが良い。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0