-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