#include <map>
#include <list>
template < typename K, typename V>
class LruCache
{
private:
typedef std::pair< K, V > EntryPair;
typedef std::list< EntryPair > CacheList;
typedef std::map< K, CacheList::iterator > CacheMap;
public:
LruCache(){}
~LruCache(){}
};
, если я попробую просто
кеш LruCache;
Я получаю следующую ошибку компиляции:
LruCache.h:17:46: error: type/value mismatch at argument 2 in template parameter list for ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’
LruCache.h:17:46: error: expected a type, got ‘LruCache<K, V>::CacheList:: iterator’
LruCache.h:17:46: error: template argument 4 is invalid
Однако, если я определю класс без шаблонных типов. т.е.
class LruCache
{
private:
typedef std::pair< int, int > EntryPair;
typedef std::list< EntryPair > CacheList;
typedef std::map< int, CacheList::iterator > CacheMap;
public:
LruCache(){}
~LruCache(){}
};
Отлично компилируется.