繁体   English   中英

C ++编译错误-“命名空间std中没有名为'function'的类型”

[英]C++ Compile Error - “no type named 'function' in namespace std”

我正在为我的C ++编程类分配作业,其中涉及实现哈希映射。 我的老师给了我们一个头文件,我们需要将其与哈希映射类一起使用。 提供的头文件包含以下行:

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

根据我对C ++的(有限的)理解,这会将HashFunction类型定义为std :: function。 但是,当我编译代码时,出现错误:

./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;
        ~~~~~~~~~~~~~~~~~~~~~^

HashMap.h文件具有

#include <functional>

如果重要的话,在顶部。

有谁知道为什么我会收到这些错误?

您需要具有(至少部分)C ++ 11支持的编译器。 您正在使用哪个编译器?

只需添加:

CONFIG +=c++11

到.pro文件:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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