【问题标题】:C++ Map of Vector of Structs?结构向量的C ++映射?
【发布时间】:2011-02-09 02:14:23
【问题描述】:

所以这是我的代码的 sn-p:


    struct dv_nexthop_cost_pair
    {
      unsigned short nexthop;
      unsigned int cost;
    };

map<unsigned short, vector<struct dv_nexthop_cost_pair> > dv;

我收到以下编译器错误:

error: ISO C++ forbids declaration of `map' with no type

声明这个的正确方法是什么?

【问题讨论】:

    标签: c++ vector map


    【解决方案1】:

    您要么忘记#include 正确的标题,要么没有导入std 命名空间。我建议如下:

    #include <map>
    #include <vector>
    
    std::map<unsigned short, std::vector<struct dv_nexthop_cost_pair> > dv;
    

    【讨论】:

    • 是的...我忘记了包含。抱歉,这里是 C++ 新手。谢谢!
    【解决方案2】:

    使用类型定义

    typedef std::map<unsigned short, std::vector<struct dv_nexthop_cost_pair> > dvnexthopemap;
    dvnexthopemap db;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-26
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 2012-11-20
      相关资源
      最近更新 更多