
Hi, I'm trying to figure out how to use property_map in boost graph, after I reduce the problem to the minimal I still don't know what the problem is. Can someone help with this? Thanks in advance. Here is the simplified example: #include <iostream> #include <map> #include <string> #include <boost/property_map/property_map.hpp> using std::string; using boost::put; using boost::get; int main() { typedef std::map<std::string, int> Map; typedef boost::associative_property_map<Map> PMap; PMap map; put(map, string("acc"), 1); get(map, string("acc")); return EXIT_SUCCESS; } This version compiles OK with mingw 4.4, but crash when running. If I make a change from "PMap map;" into "PMap map();" which I think is equivalent, then this code fail to compile, and say D:\myproject\test\boost_test\property_map\pp.cpp: In function 'int main()': D:\myproject\test\boost_test\property_map\pp.cpp:15: error: no matching function for call to 'put(main()::PMap (&)(), std::string, int)' D:\myproject\test\boost_test\property_map\pp.cpp:16: error: no matching function for call to 'get(main()::PMap (&)(), std::string)' What's the problem is? -- Yaohua Xiong Traffic and Transportation Engineering College, Tongji Univ. Cao An Road 4800#, Jia Ding District, Shanghai, China

On Wed, 7 Apr 2010, Yaohua Xiong wrote:
Hi,
I'm trying to figure out how to use property_map in boost graph, after I reduce the problem to the minimal I still don't know what the problem is. Can someone help with this? Thanks in advance.
Here is the simplified example:
#include <iostream> #include <map> #include <string> #include <boost/property_map/property_map.hpp> using std::string; using boost::put; using boost::get;
int main() { typedef std::map<std::string, int> Map; typedef boost::associative_property_map<Map> PMap;
PMap map; put(map, string("acc"), 1); get(map, string("acc"));
return EXIT_SUCCESS; }
This version compiles OK with mingw 4.4, but crash when running. If I make a change from "PMap map;" into "PMap map();" which I think is equivalent, then this code fail to compile, and say
D:\myproject\test\boost_test\property_map\pp.cpp: In function 'int main()': D:\myproject\test\boost_test\property_map\pp.cpp:15: error: no matching function for call to 'put(main()::PMap (&)(), std::string, int)' D:\myproject\test\boost_test\property_map\pp.cpp:16: error: no matching function for call to 'get(main()::PMap (&)(), std::string)'
The declaration "PMap map();" declares a function named "map" that returns an object of type "PMap". Just use the original form "PMap map;" if you want to declare an actual map. -- Jeremiah Willcock

Hi, Jeremiah. Thanks for your reply.
The declaration "PMap map();" declares a function named "map" that returns an object of type "PMap". Just use the original form "PMap map;" if you want to declare an actual map.
You are right. What a stupid mistake I make, probably I've been writing Python for too long time :-). As for the original form do you have some speculation on why it's crashing? After I surf on the Internet for a while, I found a solution to the crashing problem by change the program into: #include <iostream> #include <map> #include <string> #include <boost/property_map/property_map.hpp> using std::string; using boost::put; using boost::get; int main() { typedef std::map<std::string, int> Map; typedef boost::associative_property_map<Map> PMap; Map tmp; PMap map(tmp); put(map, string("acc"), 1); get(map, string("acc")); return EXIT_SUCCESS; } -- Yaohua Xiong Traffic and Transportation Engineering College, Tongji Univ. Cao An Road 4800#, Jia Ding District, Shanghai, China

On Thu, 8 Apr 2010, Yaohua Xiong wrote:
Hi, Jeremiah. Thanks for your reply.
The declaration "PMap map();" declares a function named "map" that returns an object of type "PMap". Just use the original form "PMap map;" if you want to declare an actual map.
You are right. What a stupid mistake I make, probably I've been writing Python for too long time :-). As for the original form do you have some speculation on why it's crashing?
After I surf on the Internet for a while, I found a solution to the crashing problem by change the program into:
#include <iostream> #include <map> #include <string> #include <boost/property_map/property_map.hpp> using std::string; using boost::put; using boost::get;
int main() { typedef std::map<std::string, int> Map; typedef boost::associative_property_map<Map> PMap;
Map tmp; PMap map(tmp); put(map, string("acc"), 1); get(map, string("acc"));
return EXIT_SUCCESS; }
The associative_property_map just contains a reference to a container, not an actual container. Look at <URL:http://www.boost.org/doc/libs/1_42_0/libs/property_map/doc/associative_property_map.html> for more information (see the top paragraph). -- Jeremiah Willcock
participants (2)
-
Jeremiah Willcock
-
Yaohua Xiong