[英]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. 我正在为我的C ++编程类分配作业,其中涉及实现哈希映射。 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. 根据我对C ++的(有限的)理解,这会将HashFunction类型定义为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 HashMap.h文件具有
#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. 您需要具有(至少部分)C ++ 11支持的编译器。 Which compiler are you using?
您正在使用哪个编译器?
Just add: 只需添加:
CONFIG +=c++11
To the .pro file :) 到.pro文件:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.