C++;编译错误-";没有名为'的类型;功能';在名称空间std中; 我正在为我的C++程序设计一个任务,它包括实现一个哈希图。我的指导老师给了我们一个头文件,我们需要在hash-map类中使用它。提供的头文件包含以下行: typedef std::function<unsigned int(const std::string&)> HashFunction; typedef std::function HashFunction; 从我(有限)对C++的理解中,将类型hash函数定义为STD::Fuffic函数。但是,当我编译代码时,会出现以下错误: ./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:46:15:错误:命名空间“std”中没有名为“function”的类型 typedef std::function HashFunction; ~~~~~^ ./HashMap.h:46:23:错误:应为成员名或“;”后声明说明符 typedef std::function HashFunction; ~~~~~~~~~~~~~~~~~~~~~^

C++;编译错误-";没有名为'的类型;功能';在名称空间std中; 我正在为我的C++程序设计一个任务,它包括实现一个哈希图。我的指导老师给了我们一个头文件,我们需要在hash-map类中使用它。提供的头文件包含以下行: typedef std::function<unsigned int(const std::string&)> HashFunction; typedef std::function HashFunction; 从我(有限)对C++的理解中,将类型hash函数定义为STD::Fuffic函数。但是,当我编译代码时,会出现以下错误: ./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:46:15:错误:命名空间“std”中没有名为“function”的类型 typedef std::function HashFunction; ~~~~~^ ./HashMap.h:46:23:错误:应为成员名或“;”后声明说明符 typedef std::function HashFunction; ~~~~~~~~~~~~~~~~~~~~~^,c++,C++,HashMap.h文件已被删除 #include <functional> #包括 如果有关系的话,在高层 有人知道我为什么会出现这些错误吗?您需要一个具有(至少部分)C++11支持的编译器。您使用的是哪种编译器?只需添加: CONFIG +=c++11 CONFIG+=c++11 对于.pro文件:)它是C++11,所以这可能会有所不同。令人惊讶的是,当编译器支持充其量还是零碎的时候(至少需要一些专业知识才能找到一个支持您需要它支持的实现),一所学校已经在其作业中要求C++11

HashMap.h文件已被删除

#include <functional>
#包括
如果有关系的话,在高层

有人知道我为什么会出现这些错误吗?

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

只需添加:

CONFIG +=c++11 CONFIG+=c++11
对于.pro文件:)

它是C++11,所以这可能会有所不同。令人惊讶的是,当编译器支持充其量还是零碎的时候(至少需要一些专业知识才能找到一个支持您需要它支持的实现),一所学校已经在其作业中要求C++11了。看起来可能事与愿违……我使用的是GCC4.2,它显然不支持C++11。我切换到VisualStudio2012,现在可以使用了。谢谢!输出看起来更像叮当声,而不是GCC。你确定你在使用GCC吗?@NathanOsman:GCC的最新4.x版本现在有一个类似于Clang的输出。