我需要編寫一個函數,從矢量中刪除收到的元素。 我認爲這樣做的方法是解析向量並將迭代器與傳遞的引用進行比較。問題是,我不能比較類型對象引用類型的迭代器...C++比較向量迭代器與實例
低於實際CODE(編輯:最初我貼了大大簡化版本)
struct BufferPoint{int x; int y; float pressure; };
class QueueState
{
public:
VectorCurve *curveVector;
RasterCurve *curveRaster;
vector<BufferPoint> *curveBuffer;
QueueState(vector<BufferPoint> *_b, VectorCurve *_v, RasterCurve *_r){ curveBuffer= _b; curveVector = _v; curveRaster = _r;};
};
vector<vector<BufferPoint>> queueBuffers;
vector<QueueState> queueStates;
[...]
// FIND AND REMOVE A BUFFER OBJECT
for(std::vector<QueueState>::iterator it = queueStates.begin(); it != queueStates.end(); ++it)
{
//Remove buffer from pool (queue)
//////////////////////////////////////////////////////////////////////////
if((it->curveVector->state == CURVEDATA_STATE_FINISHED) & (it->curveRaster->state == CURVEDATA_STATE_FINISHED))
{
queueBuffers.erase(std::find(queueBuffers.begin(), queueBuffers.end(), *(it->curveBuffer))); // <-- THIS DOESNT WORK. CHECK BELOW FOR ERROR MESSAGE (1)
queueStates.erase(it);
}
//////////////////////////////////////////////////////////////////////////
}
(1)這是消息我從編譯器獲得:
Error error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const BufferPoint' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility 2956
myRef是指向的矢量。不是對緩衝區元素的引用。 ' –
「引用'buffer'的一個元素」意思是:'int&myRef = buffer [some_correct_index];' –
你從哪裏得到myRef?你真的想做什麼?刪除具有特定值的所有項目?你如何決定要刪除什麼? – doctorlove