I wan't use the multimap on my own templated class.
The following is a working example with a builtin type.
int dat[5] = {0,6,3,7,3};
typedef std::multimap< int, int > asso;
asso dict;
for (int i=0;i<5;i++){
dict.insert(make_pair(dat[i],i));
}
asso::iterator pos;
for(pos=dict.begin(); pos!=dict.end() ;pos++)
cout << pos->first <<" next "<< pos->second <<endl;
This is my non-working code with my own templated type.
template<typename T>
void test(Array<T> ai){
typedef std::multimap< Array<T>, int > asso;
asso dict;
for (int i=0 ; i<5 ; i++){
dict.insert(make_pair(ai(i),i));
}
asso::iterator pos;
for(pos=dict.begin() ; pos!=dict.end() ; pos++)
cout << pos->first <<" next "<< pos->second <<endl;
}
Where my own templated type is called 'Array<T>'.
I think the problem is related to the std::multimap using iterators,
and I've never really understood iterators, and even less how to write my own iterators for my own templates.
This is my iterator definitions and implementation in my class
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef T& reference;
typedef const T& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
// iterator support
iterator begin() { return data_; }
const_iterator begin() const { return data_; }
iterator end() { return data_+x_; }
const_iterator end() const { return data_+x_; }
thanks in advance