Reputation: 777
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
Token Lexer::getTokenType()
{
unordered_map<string,Token> tokenType;
}
This outputs these errors:
#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:
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
Upvotes: 1
Views: 5256
Reputation: 254431
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).
Upvotes: 11