C++的Map映射到结构体向量?

5
这是我的代码片段:

这是我的代码片段:


    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

这应该怎样正确声明?
2个回答

8

你可能忘记了包含正确的头文件或者没有导入 std 命名空间。我建议执行以下操作:

#include <map>
#include <vector>

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

是的...我忘记了包含文件。抱歉,我是C++新手。谢谢! - meteoritepanama

0

使用typedef

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接