If I want to make the following LRU cache class templated, how do I do it? I repeatedly get the following error:
Template argument for template type parameter must be a type; did you
forget 'typename'?"
Here's my code:
class LRU{
int capacity;
public:
std::list<std::pair<int, int>> doubly_queue;
std::unordered_map<int, std::list<std::pair<int, int>>::iterator> elems;
LRU(int c);
int get(int key);
void put(int key, int val);
};
LRU::LRU(int c){
capacity = c;
}
How do I make the whole class templated?
This is the code after templating:
template<class T>
class LRU{
int capacity;
public:
std::list<std::pair<T, T>> doubly_queue;
std::unordered_map<T, std::list<std::pair<T, T>>::iterator> elems;
LRU(T c);
int get(T key);
void put(T key, T val);
};