Thank you for your efforts Wysota.
It turns out the code does not work "because the standard says so". In other words, while this code is ok:
// bind a temporary *expression* to a const reference
const QString
& s
= QString("hello");
// bind a temporary *expression* to a const reference
const QString& s = QString("hello");
To copy to clipboard, switch view to plain text mode
this one leaves a dangling reference:
// bind a temporary *object* to a const reference
const QString
& s
= QString("hello").
append("");
// bind a temporary *object* to a const reference
const QString& s = QString("hello").append("");
To copy to clipboard, switch view to plain text mode
I believe that from a purely "technical" point of view there is nothing wrong with the second snippet (a compiler could easily generate working code), but in fact it is not supposed to work.
Bookmarks