I have a template class with a private map member
template <typename T>
class MyClass
{
public:
MyClass(){}
private:
std::map<T,T> myMap;
}
I would like to create a private method that accepts an iterator to the map
void MyFunction(std::map<T,T>::iterator &myIter){....}
However, this gets a compile error: identifier 'iterator'. I don't need to pass an abstract iterator since MyFunction knows that it is a map iterator (and will only be used as a interator for myMap) and will treat it as such (accessing and modifying myIter->second). Passing myIter->second to MyFunction is not enough since MyFunction will also need to be able to ++myIter;.
The compiler doesn't know that std::map<T,T>::iterator
is a type—it could be anything depending on what std::map<T,T>
is. You must specify this explicitly with typename std::map<T,T>::iterator
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With