boost::associative_property_map() compile error

后端 未结 1 623
[愿得一人]
[愿得一人] 2021-01-25 20:52

using this link on boost website, I am able to compile the code here. and even get the answer (example). But when I do the same by defining in a class, I get the error as follow

相关标签:
1条回答
  • 2021-01-25 21:23

    This:

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

    declares a variable and initialize it by calling the constructor with name2address. You cannot do it in a class declaration you have to do it in the class ctor :

    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) {}
    };
    

    This should solve the compilation issue, but I'm not sure it is the best possible layout depending on how you will use Test after that.

    0 讨论(0)
提交回复
热议问题