Question

I'm trying to declare an unordered map into my program in which I will map them to tokens in another file.

I need a method which returns the Token type found in Token.h (which is an enum class)

What is confusing me is that, since I want to return the mapped Tokens from the unordered_map to the enum class, what should be the return type of the method? Also, it is stating that

error: 'unordered_map' does not name a type

I am rather new to C++ and am still finding it a bit hard in this case how I should declare methods. I've read that the unordered map should be declared INSIDE a method, but since I want the value returned by the map, which should be the return type?


I tried this

Test 1

Token Lexer::getTokenType()
{
   unordered_map<string,Token> tokenType;

}

This outputs these errors: Errors

Test 2

I tried this

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <wctype.h>
#include <map>


#include "lexer.h"


using namespace std;

long Row, Col, Offset;

unordered_map<string, Token> ProtectedWords
{

}

OR

unordered_map<string, Token>::Lexer::getTokenType()
{
}

still yielded the same

Its error: Error

I know these do sound stupid, but would you mind explain to me please? As in the tutorial I followed many are, yes, called inside a method, but even that did not work


Was it helpful?

Solution

You need to include <unordered_map>.

You'll also need to enable C++11 support, if you haven't already done so: for GCC, make sure the compiler arguments include -std=c++11 (or c++0x if you're using an old compiler).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top