#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
但是,如果我定义没有模板类型的类。IE
class LruCache
{
private:
typedef std::pair< int, int > EntryPair;
typedef std::list< EntryPair > CacheList;
typedef std::map< int, CacheList::iterator > CacheMap;
public:
LruCache(){}
~LruCache(){}
};
它编译得很好。