本文介绍了'hash_map'未在此范围中使用g ++ 4.2.1声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用sgi hash_map。
I am trying to use sgi hash_map.
#include <list>
#include <iostream>
#include <string>
#include <map>
#include <cstring>
#include <tr1/unordered_map>
#include <ext/hash_map>
using namespace std;
struct eqstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) == 0;
}
};
int main()
{
hash_map<const char*, int, hash<const char*>, eqstr> months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;
cout << "september -> " << months["september"] << endl;
cout << "april -> " << months["april"] << endl;
cout << "june -> " << months["june"] << endl;
cout << "november -> " << months["november"] << endl;
}
on gcc4.2我收到错误
on gcc4.2 I am getting the error
listcheck.cc: In function 'int main()':
listcheck.cc:22: error: 'hash_map' was not declared in this scope
listcheck.cc:22: error: expected primary-expression before 'const'
listcheck.cc:22: error: expected `;' before 'const'
listcheck.cc:24: error: 'months' was not declared in this scope
/ p>
while the same code compile with 3.4.
推荐答案
包含文件< ext / hash_map>
a href =http://www.aoc.nrao.edu/~tjuerges/ALMA/STL/html/ext_2hash__map.html> GNU扩展哈希映射类,并在命名空间中声明 __ gnu_cxx
。您可以显式限定模板名称或添加:
The include file <ext/hash_map>
refers to the GNU extension hash map class and this is declared in namespace __gnu_cxx
. You can either explicitly qualify the template name or add:
using namespace __gnu_cxx;
这篇关于'hash_map'未在此范围中使用g ++ 4.2.1声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!