【发布时间】:2014-06-14 05:27:58
【问题描述】:
这是我的功能:
const vector<int>& getVInt(){
vector<int> vint;
(...)
return vint;
}
还有,
vector<int> x = getVInt();
返回:
在抛出一个实例后调用终止 'std::out_of_range'
what(): vector::_M_range_check
和
const vector<int>& x = getVInt();
什么都不返回(一个大小不同于 0 但在我使用 x.at(i) 时没有值的向量)。
我在论坛中寻找,但关于临时和 const ref 的答案并不能帮助我理解这一点。
谢谢。
【问题讨论】:
-
什么是
entitiesIds? -
搞错了,是vint。
-
您的编译器是否应该发出not提示问题的警告? (clang 3.4:
Reference to stack memory associated with local variable 'vint' returned)