簡體   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