-1
Distance distance(const vector<long> &x, const vector <short> &y)
{
Distance total = 0.0;
Distance diff;
vector <long >::const_iterator cpx=x.begin(); //terminates at this line
vector <short>::const_iterator cpy=y.begin();
vector <long>::const_iterator cpx_end=x.end();
for(;cpx!=cpx_end;++cpx,++cpy){
diff = *cpx - *cpy;
total += (diff * diff);
}
return total;
}
距离很长很长int。std :: vector使用const_iterator终止程序
我的代码终止时,我试图分配const迭代器与矢量的开始? 为什么会发生这种情况? 向量被初始化为零。
请提供调用此函数的代码(最低限度)以及您在程序终止时收到的任何错误消息。你有没有调试过这个? – 2012-03-16 12:02:20
如果你的意思是“memset(&vec,0,sizeof(vec))”和“向量初始化为零”,那么这就是你的问题。 – stefaanv 2012-03-16 12:37:32
@KerrekSB不介意,但你是盲目的不能看到cpx和cpy是迭代器声明和分配在同一行代码中.. – shofee 2012-03-16 13:16:52