Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何取消对列表的指针的引用';在C++;?(LRU缓存)_C++_Linked List_Iterator_Unordered Map_Lru - Fatal编程技术网

C++ 如何取消对列表的指针的引用';在C++;?(LRU缓存)

C++ 如何取消对列表的指针的引用';在C++;?(LRU缓存),c++,linked-list,iterator,unordered-map,lru,C++,Linked List,Iterator,Unordered Map,Lru,此处的最小可复制示例: < >我用C++实现了一个LRU缓存,使用了代码>无序的映射-/COD>和双链接列表< />。每个链表节点都是一个数组[键,值]。HashMap将整数作为键,值是指向链接列表中节点的指针/迭代器: 类LRUCache{ int max; 列表列表; 无序地图lmap; 公众: LRUCache(内部容量):最大(容量){} int get(int键){ 自动it=lmap.find(键); if(it==lmap.end())返回-1; 放置(键,(*it->秒)[0])

此处的最小可复制示例:

< >我用C++实现了一个LRU缓存,使用了代码>无序的映射-/COD>和双链接<代码>列表< />。每个链表节点都是一个数组
[键,值]
。HashMap将整数作为键,值是指向链接列表中节点的指针/迭代器:

类LRUCache{ int max; 列表列表; 无序地图lmap; 公众: LRUCache(内部容量):最大(容量){} int get(int键){ 自动it=lmap.find(键); if(it==lmap.end())返回-1; 放置(键,(*it->秒)[0]); 返回(*it->second)[0]; } 无效放置(int键,int值){ kvList.push_back({key,value}); 如果(lmap.find(key)!=lmap.end())kvList.erase(lmap.at(key)); lmap[key]=prev(kvList.end()); } }; 我在运行此代码时遇到一些问题。当我初始化它时,就像

LRUCache*LRUCache=新的LRUCache(2);
我得到以下错误:

clang++-7 -pthread -std=c++17 -o main main.cpp
In file included from main.cpp:1:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/list:63:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_list.h:60:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/ext/alloc_traits.h:49:47: error: 
      type 'int' cannot be used prior to '::' because it has no members
template<typename _Alloc, typename = typename _Alloc::value_type>
                                              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_vector.h:83:35: note: 
      in instantiation of default argument for '__alloc_traits<int>' required
      here
      typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
                                  ^~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_vector.h:339:30: note: 
      in instantiation of template class 'std::_Vector_base<int, int>'
      requested here
    class vector : protected _Vector_base<_Tp, _Alloc>
                             ^
main.cpp:16:12: note: in instantiation of template class
      'std::vector<int, int>' requested here
    if (it == lmap.end()) return -1;
clang++-7-pthread-std=c++17-o main.cpp
在main.cpp中包含的文件中:1:
在/usr/bin/./lib/gcc/x86_64-linux-gnu/8/../../../../../../include/c++/8/list:63中包含的文件中:
在/usr/bin/./lib/gcc/x86_64-linux-gnu/8/../../../../../../../include/c++/8/bits/stl_list.h:60中包含的文件中:
/usr/bin/./lib/gcc/x86_64-linux-gnu/8/../../../../../../../../include/c++/8/ext/alloc_traits.h:49:47:错误:
类型“int”不能在“:”之前使用,因为它没有成员
模板
^
/usr/bin/./lib/gcc/x86_64-linux-gnu/8/../../../../../../../../../include/c++/8/bits/stl_vector.h:83:35:注:
在实例化“\uu alloc\u traits”的默认参数时需要
在这里
typedef typename__gnu_cxx::_alloc_traits::template
^~~~~~~~~~~~~~~~~~~~~~
/usr/bin/./lib/gcc/x86_64-linux-gnu/8/../../../../../../../../include/c++/8/bits/stl_vector.h:339:30:注:
在模板类“std::_Vector_base”的实例化中
在此请求
类向量:受保护的_向量_基
^
main.cpp:16:12:注意:在模板类的实例化中
此处请求了“std::vector”
if(it==lmap.end())返回-1;

if(it==lmap.end())返回-1有什么问题

标准向量应该是什么
std::vector
只接受一个类型参数,第二个类型参数用于指定分配器。您是否想要一个
std::vector
?谢谢!这就解决了问题!