이 경우 어떻게됩니까?'const auto'에 rvalue를 할당하면 어떻게됩니까
// assume WeakPtr is valid and has not expired
const auto& something = WeakPtr.lock();
something->doStuff();
이것은 정의되지 않았습니까?
이 시나리오에서 변경 되나요?
어때요? 이 경우 const auto&
각에서
std::vector<int> getInts() { return std::vector<int>{ 1, 2, 3 }; }
const auto& ints = getInts();
내가 개체에 대한 참조를 바인딩 할, 그러나 각각의 경우에 나는 임시를 rvalue 객체에 바인딩하고 있음을 의미한다. 재앙을 초대할까요?
다음과 같이 질문이 번뜩입니다. http://stackoverflow.com/questions/42868517/why-can-you-intialize-a-const-reference-but-not-a-non-const-reference -from-an-rv 왜곡과 wherefores에 대한 유용한 해설. – user4581301
"임시"와 "rvalue"의 차이점을 알아 두는 것이 중요합니다. 후자는 엄격히 일반적입니다. 예를 들어'const int & r = 5;'와'const int & q = std :: move (5); '를 비교하자. 둘 다 rvalues, 하나는 재앙입니다. –