Compiler error when using property map get()

Hi, The get() function for property maps has me puzzled. Calling it in one context gives a compiler error, while in another context it does not. A trivial example is below. Note that the code in foo() and main() are identical. Any guesses as to why the foo() version gives a compiler error while the main() version does not? FWIW, the error is: subgraph.cpp: In member function ‘virtual void MyGraph::foo()’: subgraph.cpp:15: error: conversion from ‘boost::subgraph_global_property_map<Subgraph*, boost::adj_list_edge_property_map<boost::bidirectional_tag, size_t, size_t&, size_t, boost::property<boost::edge_index_t, size_t, boost::no_property>, boost::edge_index_t>, boost::edge_index_t>’ to non-scalar type ‘boost::adj_list_edge_property_map<boost::bidirectional_tag, size_t, size_t&, size_t, boost::property<boost::edge_index_t, size_t, boost::no_property>, boost::edge_index_t>’ requested Thanks, Trevor #include <boost/graph/adjacency_list.hpp> #include <boost/graph/subgraph.hpp> using namespace boost; typedef subgraph<adjacency_list<vecS, vecS, bidirectionalS, int, property<edge_index_t, std::size_t> > > Subgraph; typedef property_map<Subgraph, edge_index_t>::type EdgeIndexMap; class MyGraph : public Subgraph { virtual void foo(); }; void MyGraph::foo() { Subgraph g; EdgeIndexMap edgeMap = get(edge_index, g); } int main(int, char**) { Subgraph g; EdgeIndexMap edgeMap = get(edge_index, g); return 0; }

On Fri, 2 Jul 2010, Trevor Harmon wrote:
Hi,
The get() function for property maps has me puzzled. Calling it in one context gives a compiler error, while in another context it does not. A trivial example is below. Note that the code in foo() and main() are identical. Any guesses as to why the foo() version gives a compiler error while the main() version does not?
I think you may not want to inherit from Boost classes; they are not designed for that. You will probably get more predictable behavior if you just have the subgraph as a member rather than as a base class. -- Jeremiah Willcock

On Jul 2, 2010, at 5:13 PM, Jeremiah Willcock wrote:
I think you may not want to inherit from Boost classes; they are not designed for that. You will probably get more predictable behavior if you just have the subgraph as a member rather than as a base class.
I see. I'll do that then. Is there any discussion of this issue ("inheriting from Boost classes considered harmful") somewhere in the Boost docs? (I never noticed one.) Given that Boost is a C++ framework, I'm sure I won't be the last person to try to specialize the classes via inheritance. Just a simple "there be dragons here" admonition would suffice. Trevor
participants (2)
-
Jeremiah Willcock
-
Trevor Harmon