我有以下代码:
#include <string>
#include <iostream>
#include <tr1/unordered_map>
typedef std::tr1::unordered_map<unsigned long int,std::string> eoh_map;
...
int main() {
eoh_map m;
bool found = m.find(10) != m.end();
}
...
以下错误:
In file included from src/DeDuplicator_addon.cpp:29:0:
/usr/include/c++/4.5/tr1/unordered_map.h:37:19: error: expected type-specifier before ‘hash’
/usr/include/c++/4.5/tr1/unordered_map.h:37:19: error: expected ‘>’ before ‘hash’
/usr/include/c++/4.5/tr1/unordered_map.h:42:24: error: expected template-name before ‘<’ token
/usr/include/c++/4.5/tr1/unordered_map.h:42:24: error: expected ‘{’ before ‘<’ token
/usr/include/c++/4.5/tr1/unordered_map.h:42:24: error: expected unqualified-id before ‘<’ token
/usr/include/c++/4.5/tr1/unordered_map.h:86:19: error: expected type-specifier before ‘hash’
/usr/include/c++/4.5/tr1/unordered_map.h:86:19: error: expected ‘>’ before ‘hash’
/usr/include/c++/4.5/tr1/unordered_map.h:91:24: error: expected template-name before ‘<’ token
/usr/include/c++/4.5/tr1/unordered_map.h:91:24: error: expected ‘{’ before ‘<’ token
/usr/include/c++/4.5/tr1/unordered_map.h:91:24: error: expected unqualified-id before ‘<’ token
/usr/include/c++/4.5/tr1/unordered_map.h:141:28: error: wrong number of template arguments (6, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:41:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::__unordered_map’
/usr/include/c++/4.5/tr1/unordered_map.h:143:28: error: wrong number of template arguments (6, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:41:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::__unordered_map’
/usr/include/c++/4.5/tr1/unordered_map.h: In function ‘void std::tr1::swap(int&, int&)’:
/usr/include/c++/4.5/tr1/unordered_map.h:144:11: error: request for member ‘swap’ in ‘__x’, which is of non-class type ‘int’
/usr/include/c++/4.5/tr1/unordered_map.h: At global scope:
/usr/include/c++/4.5/tr1/unordered_map.h:150:28: error: wrong number of template arguments (6, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:90:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::__unordered_multimap’
/usr/include/c++/4.5/tr1/unordered_map.h:152:28: error: wrong number of template arguments (6, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:90:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::__unordered_multimap’
/usr/include/c++/4.5/tr1/unordered_map.h:152:34: error: redefinition of ‘template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, bool __cache_hash_code> void std::tr1::swap(int&, int&)’
/usr/include/c++/4.5/tr1/unordered_map.h:143:34: error: ‘template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, bool __cache_hash_code> void std::tr1::swap(int&, int&)’ previously declared here
/usr/include/c++/4.5/tr1/unordered_map.h: In function ‘void std::tr1::swap(int&, int&)’:
/usr/include/c++/4.5/tr1/unordered_map.h:153:11: error: request for member ‘swap’ in ‘__x’, which is of non-class type ‘int’
/usr/include/c++/4.5/tr1/unordered_map.h: At global scope:
/usr/include/c++/4.5/tr1/unordered_map.h:175:19: error: expected type-specifier before ‘hash’
/usr/include/c++/4.5/tr1/unordered_map.h:175:19: error: expected ‘>’ before ‘hash’
/usr/include/c++/4.5/tr1/unordered_map.h:179:48: error: ‘_Pred’ was not declared in this scope
/usr/include/c++/4.5/tr1/unordered_map.h:179:55: error: ‘_Alloc’ was not declared in this scope
/usr/include/c++/4.5/tr1/unordered_map.h:179:61: error: wrong number of template arguments (5, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:41:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::__unordered_map’
/usr/include/c++/4.5/tr1/unordered_map.h:181:49: error: ‘_Pred’ was not declared in this scope
/usr/include/c++/4.5/tr1/unordered_map.h:181:56: error: ‘_Alloc’ was not declared in this scope
/usr/include/c++/4.5/tr1/unordered_map.h:181:62: error: wrong number of template arguments (5, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:41:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::__unordered_map’
/usr/include/c++/4.5/tr1/unordered_map.h:184:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:185:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:186:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:187:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:188:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h: In constructor ‘std::tr1::unordered_map<_Key, _Tp, _Hash>::unordered_map(std::tr1::unordered_map::size_type, const std::tr1::unordered_map::hasher&, const std::tr1::unordered_map::key_equal&, const std::tr1::unordered_map::allocator_type&)’:
/usr/include/c++/4.5/tr1/unordered_map.h:195:9: error: ‘typedef int std::tr1::unordered_map<_Key, _Tp, _Hash>::_Base’ is not a non-static data member of ‘std::tr1::unordered_map<_Key, _Tp, _Hash>’
/usr/include/c++/4.5/tr1/unordered_map.h: In constructor ‘std::tr1::unordered_map<_Key, _Tp, _Hash>::unordered_map(_InputIterator, _InputIterator, std::tr1::unordered_map::size_type, const std::tr1::unordered_map::hasher&, const std::tr1::unordered_map::key_equal&, const std::tr1::unordered_map::allocator_type&)’:
/usr/include/c++/4.5/tr1/unordered_map.h:204:4: error: ‘typedef int std::tr1::unordered_map<_Key, _Tp, _Hash>::_Base’ is not a non-static data member of ‘std::tr1::unordered_map<_Key, _Tp, _Hash>’
/usr/include/c++/4.5/tr1/unordered_map.h: At global scope:
/usr/include/c++/4.5/tr1/unordered_map.h:227:19: error: expected type-specifier before ‘hash’
/usr/include/c++/4.5/tr1/unordered_map.h:227:19: error: expected ‘>’ before ‘hash’
/usr/include/c++/4.5/tr1/unordered_map.h:231:53: error: ‘_Pred’ was not declared in this scope
/usr/include/c++/4.5/tr1/unordered_map.h:231:60: error: ‘_Alloc’ was not declared in this scope
/usr/include/c++/4.5/tr1/unordered_map.h:231:66: error: wrong number of template arguments (5, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:90:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::__unordered_multimap’
/usr/include/c++/4.5/tr1/unordered_map.h:233:54: error: ‘_Pred’ was not declared in this scope
/usr/include/c++/4.5/tr1/unordered_map.h:233:61: error: ‘_Alloc’ was not declared in this scope
/usr/include/c++/4.5/tr1/unordered_map.h:233:67: error: wrong number of template arguments (5, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:90:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::__unordered_multimap’
/usr/include/c++/4.5/tr1/unordered_map.h:236:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:237:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:238:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:239:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:240:24: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h:253:16: error: ‘_Base’ is not a class or namespace
/usr/include/c++/4.5/tr1/unordered_map.h: In constructor ‘std::tr1::unordered_multimap<_Key, _Tp, _Hash>::unordered_multimap(std::tr1::unordered_multimap::size_type, const std::tr1::unordered_multimap::hasher&, const std::tr1::unordered_multimap::key_equal&, const std::tr1::unordered_multimap::allocator_type&)’:
/usr/include/c++/4.5/tr1/unordered_map.h:247:9: error: ‘typedef int std::tr1::unordered_multimap<_Key, _Tp, _Hash>::_Base’ is not a non-static data member of ‘std::tr1::unordered_multimap<_Key, _Tp, _Hash>’
/usr/include/c++/4.5/tr1/unordered_map.h: In constructor ‘std::tr1::unordered_multimap<_Key, _Tp, _Hash>::unordered_multimap(_InputIterator, _InputIterator, int, const std::tr1::unordered_multimap::hasher&, const std::tr1::unordered_multimap::key_equal&, const std::tr1::unordered_multimap::allocator_type&)’:
/usr/include/c++/4.5/tr1/unordered_map.h:257:4: error: ‘typedef int std::tr1::unordered_multimap<_Key, _Tp, _Hash>::_Base’ is not a non-static data member of ‘std::tr1::unordered_multimap<_Key, _Tp, _Hash>’
/usr/include/c++/4.5/tr1/unordered_map.h: At global scope:
/usr/include/c++/4.5/tr1/unordered_map.h:264:55: error: wrong number of template arguments (5, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:178:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::unordered_map’
/usr/include/c++/4.5/tr1/unordered_map.h:265:48: error: wrong number of template arguments (5, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:178:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::unordered_map’
/usr/include/c++/4.5/tr1/unordered_map.h: In function ‘void std::tr1::swap(int&, int&)’:
/usr/include/c++/4.5/tr1/unordered_map.h:266:11: error: request for member ‘swap’ in ‘__x’, which is of non-class type ‘int’
/usr/include/c++/4.5/tr1/unordered_map.h: At global scope:
/usr/include/c++/4.5/tr1/unordered_map.h:270:60: error: wrong number of template arguments (5, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:230:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::unordered_multimap’
/usr/include/c++/4.5/tr1/unordered_map.h:271:53: error: wrong number of template arguments (5, should be 3)
/usr/include/c++/4.5/tr1/unordered_map.h:230:11: error: provided for ‘template<class _Key, class _Tp, class _Hash> class std::tr1::unordered_multimap’
/usr/include/c++/4.5/tr1/unordered_map.h:271:59: error: redefinition of ‘template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::tr1::swap(int&, int&)’
/usr/include/c++/4.5/tr1/unordered_map.h:265:54: error: ‘template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::tr1::swap(int&, int&)’ previously declared here
/usr/include/c++/4.5/tr1/unordered_map.h: In function ‘void std::tr1::swap(int&, int&)’:
/usr/include/c++/4.5/tr1/unordered_map.h:272:11: error: request for member ‘swap’ in ‘__x’, which is of non-class type ‘int’
src/DeDuplicator_addon.cpp: At global scope:
src/DeDuplicator_addon.cpp:48:57: error: template argument 3 is invalid
src/DeDuplicator_addon.cpp:48:66: error: invalid type in declaration before ‘;’ token
我在Ubuntu上使用g ++ 4.5.2。
有人可以帮助解决此错误吗?
非常感谢,
答案 0 :(得分:5)
std::tr1::unordered_map<…>::find()
返回迭代器而不是bool
。如果要检查是否找到了条目,请执行以下操作:
bool found = m.find(10) != m.end();
答案 1 :(得分:1)
试
bool result=m.find(10) != m.end()