报错 error: invalid initialization of non-const reference of type ‘XXX &’ from an rvalue of type‘XXX‘

问题如图: 

报错 error: invalid initialization of non-const reference of type ‘XXX &’ from an rvalue of type‘XXX‘

一般情况下,属于函数参数引用临时变量错误。

解决方案:函数声明和定义中在该参数的类型前添加const关键字。
例:void test_func(string &str);
将其改为:void test_func(const string &str);
在该函数实现中的对应位置做同样的改动。

然而,由于我的程序对应位置需要更改操作,所以不能加const限定。

于是,我把报错位置的引用&操作全去掉了(得看实际情况,我这里去掉是完全不影响的),报错就解决了。

报错 error: invalid initialization of non-const reference of type ‘XXX &’ from an rvalue of type‘XXX‘