c++11 - C++ access rvalue referenced object from non rvalue object -
c++11 - C++ access rvalue referenced object from non rvalue object -
this question has reply here:
most vexing parse: why doesn't a(()); work? 5 answersthis question may sound stupid. want create sure. , maybe point me described in standard.
we cannot have rvalue referenced objects within lvalue. right?
struct a{int value;}; struct b{ b(a &&value) : a(std::forward<a>(value)){} a&& a; }; int main() { // allowed b(a()).a; // error b b(a()); b.a; homecoming 0; }
http://coliru.stacked-crooked.com/a/ea6bd617d421a8b8
b b(a());
declares function (most vexing parse). compiler error because b has no fellow member a.
to prepare issue write b b{a()}
instead.
c++ c++11 rvalue-reference
Comments
Post a Comment