C ++ Map of Vector Structures?

So here is a snippet of my code:


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

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

code>

I get the following compiler error:

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

What is the right way to declare this?

+5
source share
2 answers

Either you forgot to # include the correct headers, or you did not import the namespace std. I suggest the following:

#include <map>
#include <vector>

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

use typedef

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

All Articles