Just been doing some coding recently, and I am getting an error in this snippet of code:
It tells me " expected `;' before 'iter' ". At first I thought I had forgot a semicolon somewhere else in the file that then caused this error to be thrown, but I don't see any.Code:template <class T> void RemoveElement ( vector <T> hay_stack, T needle ) { vector<T>::iterator iter = hay_stack.begin(); while ( iter != hay_stack.end() && (*iter) != needle ) iter++; if ( (*iter) == needle ) hay_stack.erase ( iter ); }
Here's the whole file:
Code:#ifndef __AGENTS_SIMULATION_H #define __AGENTS_SIMULATION_H #include <stdio.h> #include <stdlib.h> #include <time.h> #include <vector> using namespace std; #include "world.h" namespace AgentsSimulation { extern World SimulatedWorld; void InitializeSimulation ( ); void RunIteration ( ); template <class T> int FindVectorElement ( vector <T> hay_stack, T needle ) { for ( unsigned int x = 0; x < hay_stack.size(); x++ ) { if ( hay_stack[x] == needle ) return x; } return -1; } template <class T> void RemoveElement ( vector <T> hay_stack, T needle ) { vector<T>::iterator iter = hay_stack.begin(); while ( iter != hay_stack.end() && (*iter) != needle ) iter++; if ( (*iter) == needle ) hay_stack.erase ( iter ); } } #endif /* __AGENTS_SIMULATION_H */



LinkBack URL
About LinkBacks



