对类型的非常量左值引用...无法绑定到类型的临时对象 [英] non-const lvalue reference to type ... cannot bind to a temporary of type
问题描述
我有这个问题
83:24:错误:类型为'QImage'的非常量左值引用无法绑定到类型为'QImage'的临时目录cameraimplementation.h:23:34:注意:此处将参数传递给参数'nextImage'
83:24: error: non-const lvalue reference to type 'QImage' cannot bind to a temporary of type 'QImage' cameraimplementation.h:23:34: note: passing argument to parameter 'nextImage' here
此代码所致
updateImageData(toQImage());
与
void updateImageData(QImage& nextImage);
QImage toQImage();
除了添加临时变量外,我该如何解决这个问题.
How can I solve this other than including a temporary variable.
QImage image = toQImage();
updateImageData(image);
推荐答案
您不能.
C ++标准不允许匿名临时绑定到引用,尽管某些编译器允许将其作为扩展.(允许绑定到 const
引用 .)
The C++ standard does not allow the binding of an anonymous temporary to a reference, although some compilers allow it as an extension. (Binding to a const
reference is allowed.)
除了已经存在的解决方法之外,如果可以将函数更改为采用 const QImage&
,那么效果会更好.
Aside from the workaround you already have, if you can change the function to take const QImage&
then that would be better.
这篇关于对类型的非常量左值引用...无法绑定到类型的临时对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!