Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] Can't set non-const edge_descriptor = const edge_descriptor
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-09-04 01:44:06


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net