【问题标题】:error: ‘list’ is not a member of ‘std’ and error: template argument 2 is invalid错误:“列表”不是“标准”的成员,错误:模板参数 2 无效
【发布时间】:2015-06-06 18:15:01
【问题描述】:

我正在尝试编译我的头文件,但我遇到了我无法弄清楚的错误。

我想创建一个包含 3 个映射的结构: -从单个单词映射到计数 -从单词对映射到计数 - 从单个单词映射到以下单词列表

我的头文件中的代码:

#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
#include <vector>
#include <algorithm>
#include <map>

typedef struct {

    std::map<std::string, int> firstCounts;
    std::map<std::string, int> pairCounts;
    std::map<std::string, std::list<std::string>> follows; //You can use an iterator to retrieve the values stored in the list. 

} LanguageModel;

我遇到的错误:

>   LangModel.h:24:23: error: ‘list’ is not a member of ‘std’
>      std::map<std::string, std::list<std::string>> follows; //You can use an iterator to retrieve the values stored in the list. 
>                            ^
>     LangModel.h:24:23: error: ‘list’ is not a member of ‘std’
>     LangModel.h:24:38: error: template argument 2 is invalid
>      std::map<std::string, std::list<std::string>> follows; //You can use an iterator to retrieve the values stored in the list. 
>                                           ^
>     LangModel.h:24:38: error: template argument 4 is invalid
>     LangModel.h:24:44: error: expected unqualified-id before ‘>’ token
>      std::map<std::string, std::list<std::string>> follows; //You can use an iterator to retrieve the values stored in the list.

【问题讨论】:

    标签: c++ list c++11 dictionary std


    【解决方案1】:

    #include &lt;list&gt; 呢?您缺少标题包含。

    【讨论】:

      【解决方案2】:

      你忘了添加

      #include <list>    
      

      【讨论】:

      • 谢谢!我忘记了。另外,在头文件中包含可能不会使用的库有什么问题吗?
      • 编译器有更多的工作要做,但对于一个简单的程序来说,这无关紧要。除了它的冗余......
      • .h 文件中添加#include 行具有编译时间成本。除非需要,否则不要在 .h 文件中使用 #include 任何内容。
      猜你喜欢
      • 2017-10-10
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 2013-11-21
      • 1970-01-01
      相关资源
      最近更新 更多