Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] passing a graph from one function to another
From: Andrew Sutton (andrew.n.sutton_at_[hidden])
Date: 2008-11-19 11:29:09


>
> 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...
> }
>
>
You can't invoke a constructor on an object that is already created - well,
you probably can, but I seriously doubt that you want to. Instead, just
return myGraph from fun_A:

graph_t fun_A()
{ return graph_t(...); }

func_B(graph_t& g)
{ ... }

main()
{
  graph_t g = fun_A();
  fun_B(g);
}

It might look like there's an unnecessary copy, but there won't be.

Andrew Sutton
andrew.n.sutton_at_[hidden]



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