I have a template class that contains a std::map
that stores pointers to T which refuses to compile:
template
class Foo
{
public
You need:
typename std::map<int, T*>::const_iterator begin() const { return items.begin(); }
Or simpler
typedef typename std::map<int, T*>::const_iterator const_iterator;
const_iterator begin() const { return items.begin(); }
This is because const_iterator
is dependent name on T
so you need to tell compiler that it is actually type.
Use typename
:
typename std::map<int, T*>::const_iterator begin() const ...
When this is first passed by the compiler, it doesn't know what T
is. Thus, it also doesn't know wether const_iterator
is actually a type or not.
Such dependent names (dependent on a template parameter) are assumed to
typename
template
.You need typename
:
typename std::map<int, T*>::const_iterator begin() const { return items.begin(); }