Neal Young
Neal Young

Reputation: 203

C++ Compile Error - "no type named 'function' in namespace std"

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?

Upvotes: 4

Views: 6927

Answers (2)

xlarsx
xlarsx

Reputation: 991

Just add:

CONFIG +=c++11

To the .pro file :)

Upvotes: 0

Andreas Brinck
Andreas Brinck

Reputation: 52519

You need a compiler with (at least partial) C++11 support. Which compiler are you using?

Upvotes: 6

Related Questions