I have a class that internally has an instance of map:
template<typename K, typename V>
class my_map {
private:
std::map<K, V> mmap;
Internally to the class I need to create an iterator for templated types, how can I do this?
To avoid confusion with typename
keyword. I suggest to do the following
template<typename K, typename V>
class my_map {
private:
std::map<K, V> mmap;
public:
typedef typename std::map<K, V>::iterator iterator;
typedef typename std::map<K, V>::const_iterator const_iterator;
iterator begin() {return mmap.begin();}
const_iterator begin() const {return mmap.begin();}
.
.
.
};
You can now use it as my_map<K, V>::iterator
or my_map<K, V>::const_iterator
.