0

I know exactly similar questions have been already proposed, but those questions focus on how to create a new template class. My question is about how to use existing template classes such as std::list, std::map, which makes it even more confusing for me.

I am now creating a template class for LRU Caching. I do it like this:

template <typename KT, typename VT>
class LRUCache{
private:
    struct Node{
        KT key;
        VT value;
        Node(KT k, VT v) : key(k), value(v) {}
    };
public:
    LRUCache(int c) : capacity(c) {}

    VT get(KT key) { ... }
    void set(KT key, VT value) { ... }

private:
    int capacity;

    std::list<Node> cacheList;
    std::unordered_map<KT, std::list<Node>::iterator> cacheMap;
};

I got an error type/value mismatch at argument 2 in template parameter list for ‘template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> class std::unordered_map’. It seems confusing for me to understand this. One of the previous proposed problems mentions that std::list has more than one class parameters in its template, and now std::unordered_map seems to have 5. What should I do know?

Daniel Shao
  • 137
  • 1
  • 8

0 Answers0