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

I am working on an assignment for my C ++ programming class, which includes a hash map implementation. My instructor gave us a header file that we should use with our hash class. The provided header file contains the line:

typedef std::function<unsigned int(const std::string&)> HashFunction; 

From my (limited) understanding of C ++, this will define the HashFunction type as std :: function. However, when I compile the code, I get 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; ~~~~~~~~~~~~~~~~~~~~~^ 

There is a HashMap.h file

 #include <functional> 

above if that matters.

Does anyone know why I am getting these errors?

+4
source share
2 answers

You need a compiler with (at least partial) support for C ++ 11. Which compiler do you use?

+6
source

Just add:

  CONFIG + = c ++ 11

To the .pro file :)

0
source

Source: https://habr.com/ru/post/1443872/


All Articles