Boost Graph: add_edge causes compiler error

Hi,
Could someone please help me understand why the simple program below
won't compile? On the call to add_edge, I get:
error: invalid conversion from ‘Foo*’ to ‘long unsigned int’
...followed by two "initializing argument" errors.
I've read all the docs I could find on add_edge, but I still don't
understand why the code below won't work. Thanks for any help,
Trevor
#include "boost/graph/adjacency_list.hpp"
using namespace boost;
typedef struct FooType {
} Foo;
int main() {
typedef adjacency_list

On Mar 26, 2010, at 3:54 PM, Andrew Sutton wrote:
you should just be able to write:
add_edge(0, 1, g)
Is there a way to add an edge if I don't know the vertex indices? For instance, let's say I've only got the two Foo pointers and I want to add an edge between them. I suppose I could iterate through all vertices in the graph, find the Foo pointer, and thus know its index, but I feel like there must be a better (and faster) way. Thanks for any hints, Trevor

you should just be able to write:
add_edge(0, 1, g)
Is there a way to add an edge if I don't know the vertex indices? For instance, let's say I've only got the two Foo pointers and I want to add an edge between them.
I suppose I could iterate through all vertices in the graph, find the Foo pointer, and thus know its index, but I feel like there must be a better (and faster) way.
A common approach is to keep a map or unordered_map from Foo to vertex
descriptor. You can think of a descriptor is a kind of generalized index.
For example:
typedef graph_traits<Graph>::vertex_descriptor Vertex;
map

On Mar 26, 2010, at 4:52 PM, Trevor Harmon wrote:
Is there a way to add an edge if I don't know the vertex indices? For instance, let's say I've only got the two Foo pointers and I want to add an edge between them.
I figured out a way to do it: graph_traits<Graph>::vertex_descriptor u = add_vertex(&foo1, g); graph_traits<Graph>::vertex_descriptor v = add_vertex(&foo2, g); add_edge(u, v, g); Trevor

Is there a way to add an edge if I don't know the vertex indices? For
instance, let's say I've only got the two Foo pointers and I want to add an edge between them.
I figured out a way to do it:
graph_traits<Graph>::vertex_descriptor u = add_vertex(&foo1, g); graph_traits<Graph>::vertex_descriptor v = add_vertex(&foo2, g); add_edge(u, v, g);
That's the right way :) I think I must have misunderstood your previous question. Andrew Sutton andrew.n.sutton@gmail.com
participants (2)
-
Andrew Sutton
-
Trevor Harmon