C++ boost::关联属性映射()编译错误

C++ boost::关联属性映射()编译错误,c++,boost,map,boost-graph,C++,Boost,Map,Boost Graph,使用boost网站上的这个链接,我能够编译代码。甚至可以得到答案(例如)。但当我通过在类中定义来执行相同操作时,我会得到如下错误: #include < as usual in the code > class Test{ std::map<std::string, std::string> name2address; boost::const_associative_property_map< std::map<std::string, std::s

使用boost网站上的这个链接,我能够编译代码。甚至可以得到答案(例如)。但当我通过在类中定义来执行相同操作时,我会得到如下错误:

#include < as usual in the code >

class Test{

 std::map<std::string, std::string> name2address;
 boost::const_associative_property_map< std::map<std::string, std::string> >
                  address_map(name2address);


};
我必须按如下方式使用typedef和typename来正确编译代码。但我仍然无法使用(insert或foo函数(如示例所示)

请帮助,这是使用typedefs的代码

class Test{
  typedef typename std::map<std::string, std::string> name2address;
  boost::const_associative_property_map< std::map<std::string, std::string> >
                address_map(name2address);

 };
类测试{
typedef typename std::map name2address;
boost::const\u关联属性\u映射
地址映射(name2address);
};
我必须将此关联属性映射传递给另一个类,在该类中我可以像往常一样使用get和put函数。我将如何处理它?

这:

boost::const_associative_property_map< std::map<std::string, std::string> > address_map(name2address);
boost::const\u associative\u property\u mapaddress\u map(name2address);
声明一个变量,并通过使用name2address调用构造函数对其进行初始化。不能在类声明中执行此操作,必须在类声明中执行此操作:

class Test{

 std::map<std::string, std::string> name2address;
 boost::const_associative_property_map< std::map<std::string, std::string> >
                  address_map;
public:
 Test() : address_map(name2address) {}
};
类测试{
std::map name2address;
boost::const\u关联属性\u映射
地址图;
公众:
Test():地址映射(name2address){
};

这应该可以解决编译问题,但我不确定它是否是最好的布局,这取决于之后您将如何使用Test。

谢谢,问题是,我已经在一个静态类中声明了这一点,但我将该类作为模板参数传递给另一个类。我想在新类中使用映射。标记的问题正是因为这个原因,才复制了这本书。
class Test{

 std::map<std::string, std::string> name2address;
 boost::const_associative_property_map< std::map<std::string, std::string> >
                  address_map;
public:
 Test() : address_map(name2address) {}
};