I'm working on an assignment for my C++ programming class which involves implementing a hash map. My instructor has given us a header file that we are required to use with our hash map class. The provided header file contains the line:
typedef std::function<unsigned int(const std::string&)> HashFunction;
From my (limited) understanding of C++, this would define the type HashFunction as a std::function. However, when I compile the code, I get the errors:
./HashMap.h:46:15: error: no type named 'function' in namespace 'std'
typedef std::function<unsigned int(const std::string&)> HashFunction;
~~~~~^
./HashMap.h:46:23: error: expected member name or ';' after declaration specifiers
typedef std::function<unsigned int(const std::string&)> HashFunction;
~~~~~~~~~~~~~~~~~~~~~^
The HashMap.h file has
#include <functional>
at the top, if it matters.
Does anyone know why I'm getting these errors?
You need a compiler with (at least partial) C++11 support. Which compiler are you using?
Just add:
CONFIG +=c++11
To the .pro file :)
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.