2010-04-17 75 views
5

因此,这里是我的代码片段:结构向量的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 

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

回答

8

要么你忘了#include正确的头文件或没有导入std命名空间。我建议如下:

#include <map> 
#include <vector> 

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

是啊......我忘了包括。对不起,这里是C++ newb。谢谢! – garsh0p 2010-04-17 06:36:57

0

使用的typedef

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