Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

non-const lvalue reference to type ... cannot bind to a temporary of type [duplicate]

Tags:

c++

I have this problem

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

caused by this code

updateImageData(toQImage());

with

void updateImageData(QImage& nextImage);
QImage toQImage();

How can I solve this other than including a temporary variable.

QImage image = toQImage();
updateImageData(image);
like image 751
Matthias Pospiech Avatar asked Sep 03 '25 04:09

Matthias Pospiech


1 Answers

You can't.

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.)

Aside from the workaround you already have, if you can change the function to take const QImage& then that would be better.

like image 122
Bathsheba Avatar answered Sep 04 '25 20:09

Bathsheba