结构向量的C++映射?
问题描述:
因此,这里是我的代码片段:结构向量的C++映射?
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
什么是这个声明的正确方法?
答
要么你忘了#include正确的头文件或没有导入std
命名空间。我建议如下:
#include <map>
#include <vector>
std::map<unsigned short, std::vector<struct dv_nexthop_cost_pair> > dv;
答
使用的typedef
typedef std::map<unsigned short, std::vector<struct dv_nexthop_cost_pair> > dvnexthopemap;
dvnexthopemap db;
是啊......我忘了包括。对不起,这里是C++ newb。谢谢! – garsh0p 2010-04-17 06:36:57