Can't bind lvalue to rvalue reference

后端 未结 2 887
野的像风
野的像风 2021-01-12 11:49

I have this C++ test code snippet,

#include 

class A {
        std::vector x;
public:
             


        
相关标签:
2条回答
  • 2021-01-12 12:06

    Anything that has a name is an lvalue reference. You have to use std::move on parameters to pass them on as rvalue references.

    0 讨论(0)
  • 2021-01-12 12:23

    Quote from WIKI

    For safety reasons, some restrictions are imposed. A named variable will never be considered to be an rvalue even if it is declared as such. To get an rvalue, the function template std::move() should be used. Rvalue references can also be modified only under certain circumstances, being intended to be used primarily with move constructors.

    0 讨论(0)
提交回复
热议问题