いくつかの情報(id、position(x、y)、frameNumber)を持つfirstAppという名前のベクトルを埋めたいと思います。したがって、ベクトルを既存の情報で埋めないように条件を作ります。std :: findをループで使用する方法
std::vector<FirstAppearance>::iterator p;
for (int idxCurrent = 0; idxCurrent < nOfPedcurrFrame ; idxCurrent++)
{
if(nOfPedprevFrame == 0)
{
CurrentId=frames[frameNumber].GetPedest()[idxCurrent].GetID();
FA=FirstAppear(frames,CurrentId,idxCurrent);
FirstPosition=frames[FA].GetPedest()[idxCurrent].GetPosition();
f.SetFrameNumber(FA);
f.SetFirstPosition(FirstPosition);
f.SetFId(CurrentId);
if(firstApp.size() !=0)
{
p=std::find(firstApp.begin(),firstApp.end(),f);
std::cout << *p<< endl;
if(p == firstApp.end())
{
firstApp.push_back(f);
}
}
else
{
firstApp.push_back(f);
}
f.~FirstAppearance();
}
}
FirstAppearnce.cpp:
#include "stdafx.h"
#include "FirstAppearance.h"
#include <iostream>
FirstAppearance::FirstAppearance(){}
int FirstAppearance::GetFId(void)const {return fId;}
objectCoordinates FirstAppearance::GetFirstPosition(void)const {return firstPosition;}
void FirstAppearance::SetFirstPosition(objectCoordinates pos){firstPosition =pos;}
void FirstAppearance::SetFId(int id){fId =id;}
int FirstAppearance::GetFrameNumber(void)const {return fNumber;}
void FirstAppearance::SetFrameNumber(int fnumb){ fNumber = fnumb;}
bool FirstAppearance::operator==(const FirstAppearance& a){
if((firstPosition.x == a.firstPosition.x) && (firstPosition.y == a.firstPosition.y) &&
(fId==a.fId) && (fNumber==a.fNumber)){
return true;
}
}
FirstAppearance::~FirstAppearance(){}
私はSTDを使用する:: fが、私は、pは、このような値を持っていたことだ私のプログラムをコンパイルするときにそれをon.But埋めるために私のベクターに存在するかどうか検索する見つけます私のprogram.Canの人生に沿ってfの最初の値は、なぜstd :: findがfの値を新しい値で更新しなかったか教えてください。 * pの 出力は次のようになります。
1 263 138 0
1 263 138 0
1 263 138 0
1 263 138 0
1 263 138 0
: 次のようなものを持っている必要があります。 –
'f。〜FirstAppearance();'疑わしく見える –
'p == firstApp.end()'が未定義の動作であるときに 'p'を間接参照します。スマートコンパイラは 'if(p == firstApp.end())チェックを最適化し、常に' firstApp.push_back(f); 'を実行します。また、 'f。〜FirstAppearance();'は、あなたがすることを意味するものではありません。 – nwp