I am creating a Set class using the standard list
container. When I declare the list iterator iter
, I get an error:
C3861 'iter':identifier not found
I have found a few examples of other people declaring list iterators in this way, but I may be misunderstanding something about iterators.
#include <list>
#include <iterator>
using namespace std;
template <typename T>
class Set
{
private:
list<T> the_set;
list<T>::iterator iter;
public:
Set() {}
virtual ~Set() {}
void insert(const T& item) {
bool item_found = false;
for (iter = the_set.begin(); iter != the_set.end(); ++iter) {
if (*iter == item) item_found = true;
}
if (!item_found) {
iter = the_set.begin();
while (item > *iter) {
++iter;
}
the_set.list::insert(iter, item);
}
}
}
The error is shown happening at the line:
list<T>::iterator iter;