I am trying to compile the following code on Linux using gcc 4.2:
#include <map>
#include <list>
template<typename T>
class A
{
...
private:
std::map<const T, std::list<std::pair<T, long int> >::iterator> lookup_map_;
std::list<std::pair<T, long int> > order_list_;
};
When I compile this class I receive the following message from gcc:
error: type/value mismatch at argument 2 in template parameter list for ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’
error: expected a type, got ‘std::list<std::pair<const T, long int>,std::allocator<std::pair<const T, long int> > >::iterator’
error: template argument 4 is invalid
I have removed file names and line numbers , but they all refer to the line declaring the map.
When I replace the pair in these expressions with an int or some concrete type, it compiles fine. Can someone please explain to me what I am doing wrong.
You need to write typename
before std::list<...>::iterator
, because iterator
is a nested type and you're writing a template.
Edit: without the typename
, GCC assumes (as the standard requires) that iterator
is actually a static variable in list
, rather than a type. Hence the "parameter type mismatch" error.
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