不能在增强/unordered_map中使用矢量

Can not use a vector in boost/unordered_map

本文关键字:map 增强 unordered 不能      更新时间:2023-10-16

我正在使用unordered_map,但我无法将指针向量声明为值。我有以下声明:

//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;

我已经在test.cpp中包含这个头文件,当我使用g ++编译时,出现以下错误:

/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

知道这个错误是什么意思吗?

您缺少std::vectorstd::string分别需要的vectorstring标头。

您也应该包括utility,以便std::pair。这可能包含在boost/unordered_map.hpp中,但您不应该依赖它。

#include <vector>
#include <string>
#include <utility>