Iterators and Templates of Templates

Hi All,

I am getting compile errors that I don't understand when trying to declare an STL map iterator within a templated class function. My pruned code snippets of interest are:

template<class T> class agrDataFieldValue {
public:
agrDataFieldValue(T value);
~agrDataFieldValue();

private:
T _value;
};

template<class O, class T> class agrDataField {
public:
agrDataField();
~agrDataField();

bool addValue(O obj, T value);

private:
map<O, agrDataFieldValue<T>*> _values;
};


template<class O, class T> bool agrDataField<O, T>::addValue(O obj, T value) {
map<O, agrDataFieldValue<T>* >::iterator iter = _values.find(obj);
}

The compile error I get is:

db/agrGraph.cpp: In member function `bool agrDataField<O, T>::addValue(O, T)':
db/agrGraph.cpp:758: error: expected `;' before "iter"

where line 758 corresponds to:

map<O, agrDataFieldValue<T>* >::iterator iter = _values.find(obj);


I've tried various forms of typedef's to try to simplify the declaration for the compiler but it generally all leads to the same error.

Any one have any ideas ?? Is there something obvious I'm missing ??

BTW, My compiler version is:

GNU C++ version 3.4.6 20060404 (Red Hat 3.4.6-9) (i386-redhat-linux)
compiled by GNU C version 3.4.6 20060404 (Red Hat 3.4.6-9).


For now I've changed the STL map to use a pair of void* values and I'll do appropriate casting but I'd preferred to do it correctly as I was originally intending.

Thanks for any help.

Tim

(edit: Fixed typos)
Last edited on
First thing to try is using typename:

1
2
3
4
template<class O, class T> bool agrDataField<O, T>::addValue(O obj, T value) 
{
   typename std::map<O, agrDataFieldValue<T>* >::iterator iter = _values.find(obj);
}


and see if that fixes the compile error.
Bingo. That's it. Thanks!!
Topic archived. No new replies allowed.