[BGL] Can't set non-const edge_descriptor = const edge_descriptor

I have struct edge_properties { Traits::edge_descriptor ePredecessor; } some_function ( const Graph g ) { e = edge(vertex_a, vertex_b, g).first; //fails here g[e].ePredecessor = e; } compiler gives ./Includes/Utilities.cpp:451: error: passing ‘const boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>’ as ‘this’ argument of ‘boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>& boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>::operator=(const boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>&)’ discards qualifiers make: *** [pl] Error 1 My guess is that e is returned as a const but g[e].ePredecessor is declared a variable. How can I fix this? Thanks John

On Fri, 3 Sep 2010, John Robertson wrote:
I have
struct edge_properties { Traits::edge_descriptor ePredecessor; }
some_function ( const Graph g ) {
e = edge(vertex_a, vertex_b, g).first;
//fails here g[e].ePredecessor = e;
}
compiler gives
./Includes/Utilities.cpp:451: error: passing ‘const boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>’ as ‘this’ argument of ‘boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>& boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>::operator=(const boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>&)’ discards qualifiers make: *** [pl] Error 1
My guess is that e is returned as a const but g[e].ePredecessor is declared a variable. How can I fix this?
The issue is actually (it appears) that since g is const, you cannot write to its properties. Note that the error message is about passing a const object as "this" to the operator=() call, not about the argument to the call. -- Jeremiah Willcock
participants (2)
-
Jeremiah Willcock
-
John Robertson