returning pointer to Boost::assign::map_list_of
Hi, I am new to Boost::Assign. I have a std::map<std::string, unsigned char> and I have a SomeClass with constructor SomeClass(std::string, std::map<std::string, unsigned char>*) and I want to pass the pointer to the result of map_list_of to SomeClass like this: SomeClass *psc = new SomeClass("SomeClassName",map_list_of("one",1)("two",2)("three",3)("four",4)("five",5); In the example at http://www.boost.org/doc/libs/1_43_0/libs/assign/doc/index.html#intro , the map_list_of is definitely returning a small map. I don't want to pass the map object itself but the pointer to the map object returned by map_list_of. Please help me. -Best regards
alapex0310@gmail.com skrev:
Hi,
I am new to Boost::Assign.
I have a std::map<std::string, unsigned char> and I have a SomeClass with constructor SomeClass(std::string, std::map<std::string, unsigned char>*) and I want to pass the pointer to the result of map_list_of to SomeClass like this:
SomeClass *psc = new SomeClass("SomeClassName",map_list_of("one",1)("two",2)("three",3)("four",4)("five",5);
In the example at http://www.boost.org/doc/libs/1_43_0/libs/assign/doc/index.html#intro , the map_list_of is definitely returning a small map. I don't want to pass the map object itself but the pointer to the map object returned by map_list_of.
map_list_of returns an unspecified type that converts to a map. So you have two options: 1. change your argument to map<string,unsigned char> 2. make your constructor a template, and let the "map" argument be const T& mapValues instead (I'm assuming you are going to initialize a map in the constructor. 2) might be more efficient, if that matters -Thorsten
participants (2)
-
alapex0310@gmail.com
-
Thorsten Ottosen