简体   繁体   中英

C++ unordered map error

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:错误

Test 2

I tried this

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

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


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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM