Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] passing a graph from one function to another
From: r89 (r8921025_at_[hidden])
Date: 2008-11-19 11:39:02


James Sutherland-4 wrote:
>
>
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>

I do have graph typedef as a global.
The original problem was, I am not allowed to define
graph_t myGraph;
without all the arguments like this:
graph_t myGraph(array, edge_array + num_arcs, weights, num_nodes);

Since I don't know the arguments before fun_A, I need something like a
"resize" operator, so that i can define graph_t outside the function, but
declare it later inside the function.

Any suggestions?
Thanks!

-- 
View this message in context: http://www.nabble.com/-BGL--passing-a-graph-from-one-function-to-another-tp20582781p20583776.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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