0
它危險返回一個參考包裝紙等,顯示如下:返回C++參考包裝
std::vector<std::reference_wrapper<int>> foo() {
int x = 10;
std::vector<std::reference_wrapper<int>> vec;
vec.push_back(x);
return vec;
}
foo2() {
std::cout << foo()[0] << std::endl;
}
我假定本地/堆棧變量x可以在foo2()
丟失。
通常的懸掛指針/參考 –