Question

I am using unordered_map and I am unable to declare a vector of pointers as value. I have the following declarations:

//file test.h

#include <boost/unordered_map.hpp>
#include <boost/foreach.hpp>

struct Record
{
    char **data;
};

typedef boost::unordered_map<std::string, std::vector<Record*> > MAP;
typedef std::pair<std::string,std::vector<Record*> > PAIR;

I have included this header file in test.cpp, and When I compile using g++, I get the following error:

/usr/include/boost/detail/container_fwd.hpp:80: error: provided for ‘template<class T,   class Allocator> struct std::vector’
test.h:10: error: template argument 2 is invalid
test.h:10: error: template argument 5 is invalid
test.h:10: error: invalid type in declaration before ‘;’ token

Any idea what this error means?

Was it helpful?

Solution

You are missing the vector and string headers, needed for std::vector and std::string respectively.

You should include utility too, for std::pair. This may be included by boost/unordered_map.hpp, but you shouldn't rely on that.

#include <vector>
#include <string>
#include <utility>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top