|
Boost Users : |
Subject: Re: [Boost-users] [BGL] passing a graph from one function to another
From: James Sutherland (James.Sutherland_at_[hidden])
Date: 2008-11-19 11:27:25
On Nov 19, 2008, at 8:54 AM, r89 wrote:
>
> Hi all,
>
> I have a graph defined as follows (the same as in the Dijkstra
> shortest path
> example code):
>
> typedef adjacency_list < listS, vecS, directedS, no_property,
> property <
> edge_weight_t, float > > graph_t;
>
> The following works fine:
> graph_t myGraph(array, edge_array + num_arcs, weights, num_nodes);
>
> However, now I want to do the above line inside a function (say,
> fun_A), and
> I want another function (say, fun_B) to have access to "myGraph".
>
> How should I do that? I wish I could do something like this:
>
> graph_t myGraph;
>
> fun_A(graph_t &myGraph) {
> myGraph(array, edge_array + num_arcs, weights, num_nodes);
> }
>
> fun_B(graph_t &myGraph) {
> // using myGraph to run some graph algorithm...
> }
>
If you don't have the graph typedef as a global, then a reasonable
option is to use a function template for fun_B:
template<typename GraphT>
fun_B( GraphT& graph ){
// operate on graph...
}
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