g++上的无序映射

Unordered Maps on g++

本文关键字:映射 无序 g++      更新时间:2023-10-16

我目前正在学习STL,并试图为字典文件实现一个无序映射。

这是我第一次这样做,所以在尝试之前我做了很多研究。

我想为我的作业做一个无序的地图,因为如果我们能让我们的项目比教授目前的解决方案更快,我们就能获得额外的分数

我遇到的问题是,我一直得到这个错误:

SpellCheck.h:16:错误:ISO C++禁止在没有类型的情况下声明"无序映射"

我确信我的语法是正确的,但我可能遗漏了一些东西。

我不确定这是否有帮助,但我正在学校服务器上使用g++进行编译。

我的g++版本是g++(GCC)4.4.7.

#ifndef SPELLCHECK_H
#define SPELLCHECK_H
#include <vector>
#include <tr1/unordered_map>
#include <string>

using std::vector;
using std::string;

class SpellCheck
{
private:
typedef vector<string> Vector;
typedef unordered_map<string, int> Dictionary;  
};
#endif

这也应该有效。使用-std=c++0x标志编译,以使用带有g++的c++11。

#ifndef SPELLCHECK_H
#define SPELLCHECK_H
#include <vector>
#include <unordered_map>
#include <string>
class SpellCheck
{
private:
    typedef std::vector<std::string> Vector;
    typedef std::unordered_map<std::string, int> Dictionary;  
};
#endif