MipsMoreLikeWhips
MipsMoreLikeWhips

Reputation: 147

Unordered Maps on g++

I am learning about STL currently and I am trying to implement an unordered map for a dictionary file.

This is the first time I have done this so I did a lot of research prior to trying this.

I want to do an unordered map for my assignment because we can receive extra points if we can make our project faster than what our professor's solution currently is.

The problem I am running into is that I keep getting this error:

SpellCheck.h:16: error: ISO C++ forbids declaration of âunordered_mapâ with no type

I am sure my syntax is correct, but I could be missing something.

I am not sure if this helps, but I am compiling on a school server using g++.

My g++ version is 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

Upvotes: 0

Views: 1397

Answers (1)

wangjunwww
wangjunwww

Reputation: 296

This should also work. Compile with -std=c++0x flag to use c++11 with g++.

#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

Upvotes: 3

Related Questions