2014-03-03 40 views
0

我正在使用unordered_map,我無法將指針向量聲明爲值。我有以下聲明:不能在boost/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 

任何想法,這個錯誤是什麼手段?

+0

是否有可能MAP是在代碼的某個地方定義的宏? – Loghorn

+0

哪一行導致問題? –

+4

請發佈一個自包含的測試用例。用你當前的代碼,可以說你缺少至少兩個重要的頭文件。 – juanchopanza

回答

3

您錯過了vectorstring標頭,分別需要std::vectorstd::string

您也應該包括utility,對於std::pair。這可能包括boost/unordered_map.hpp,但你不應該依賴於此。

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