Hi guys,
I'm cleaning up some code for a project and I'm running into trouble.
I have a vector of objects called mObjectList which displays primitives to be drawn on screen. I have a function to add new objects to the vector, and am now making a function to remove objects.
I have a crappy way that works but I would really like to do it the proper way by using an iterator, and here is where I am running into problems. I seriously don't know why I am having such a hard time with this (I think I just need to step away from my code but its not an option right now :/ )
Here is where I declare my iterator:
And here is my function to remove an element (note the pseudocode section)
There is code I am referencing from a book I have that is doing this exact same thing with no problems, I however receive the error "Invalid operands to binary expression ('GraphicsObject' and 'GraphicsObject').
What I want the code to do is simply compare the object passed to it with its location in the mObjectList vector and delete itself. Anyone have any suggestions?
Also it should be noted I never use vectors so it could be something completely obvious I'm overlooking.
EDIT: I should also note that originally I tried this:
Declare iterator
And here is the function to remove the element in the code:
But, this doesn't work either since the objects are not of int type.
I'm cleaning up some code for a project and I'm running into trouble.
I have a vector of objects called mObjectList which displays primitives to be drawn on screen. I have a function to add new objects to the vector, and am now making a function to remove objects.
I have a crappy way that works but I would really like to do it the proper way by using an iterator, and here is where I am running into problems. I seriously don't know why I am having such a hard time with this (I think I just need to step away from my code but its not an option right now :/ )
Here is where I declare my iterator:
Code:
//Iterator to cycle through the mObjectList
vector<GraphicsObject>::const_iterator iter;
And here is my function to remove an element (note the pseudocode section)
Code:
void OGLApp::removeElement(GraphicsObject &object)
{
//Pseudocode
for(iter = mObjectList.begin(); iter != mObjectList.end(); ++iter)
{
if(*iter == object)
mObjectList.pop_back();
}
}
There is code I am referencing from a book I have that is doing this exact same thing with no problems, I however receive the error "Invalid operands to binary expression ('GraphicsObject' and 'GraphicsObject').
What I want the code to do is simply compare the object passed to it with its location in the mObjectList vector and delete itself. Anyone have any suggestions?
Also it should be noted I never use vectors so it could be something completely obvious I'm overlooking.
EDIT: I should also note that originally I tried this:
Declare iterator
Code:
//Iterator to cycle through the mObjectList
vector<int>::const_iterator iter;
And here is the function to remove the element in the code:
Code:
void OGLApp::removeElement(GraphicsObject &object)
{
//Pseudocode
for(iter = mObjectList.begin(); iter != mObjectList.end(); ++iter)
{
if(*iter == object.ID())
mObjectList.pop_back();
}
}
But, this doesn't work either since the objects are not of int type.
Last edited: