Can't bind lvalue to rvalue reference

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

I have this C++ test code snippet,

#include 

class A {
        std::vector x;
public:
             


        
2条回答
  •  生来不讨喜
    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.

提交回复
热议问题