Hello, I'm creating a program that will require a vector, of dynamic size, of subgraphs. so let's suppose I have something like this: typedef subgraph< adjacency_list > Graph; Graph G; what I want is to create a: vector< Graph& > subG; but the usage of & here is illegal. Do you guys have any suggestion on how to do it? regards,
oh sorry, forgot to mention, after
vector< Graph& > subG;
I should have something like:
subG.resize(2);
subG(0) = G.subgraph();
and subgraph() returns a Graph&
On 7 abr, 21:04, "James C. Sutherland"
On Apr 7, 2009, at 4:59 PM, fabricio wrote:
typedef subgraph< adjacency_list > Graph;
Graph G;
what I want is to create a:
vector< Graph& > subG;
but the usage of & here is illegal.
Why not use pointers? vector
subG; or vector< boost::shared_ptr<Graph> > subG; _______________________________________________ Boost-users mailing list Boost-us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users
Agree with James, shared_ptr can help here... typedef subgraphGraph; typedef shared_ptr GraphPtr; typedef vector Graphs; Graphs graphs; graphs.push_back(GraphPtr(new Graph)); or perhaps Graphs graphs; graphs.resize(2); graphs[1].reset(new Graph); graphs[1]->DoStuff(); graphs[0] = GraphPtr(new Graph); graphs[0]->DoStuff(); ~Damian(); > -----Original Message----- > From: boost-users-bounces@lists.boost.org [mailto:boost-users- > bounces@lists.boost.org] On Behalf Of fabricio > Sent: Wednesday, 8 April 2009 2:54 p.m. > To: boost-users@lists.boost.org > Subject: Re: [Boost-users] a vector of subgraphs > > oh sorry, forgot to mention, after > > vector< Graph& > subG; > > I should have something like: > > subG.resize(2); > subG(0) = G.subgraph(); > > and subgraph() returns a Graph& > > On 7 abr, 21:04, "James C. Sutherland" > wrote: > > On Apr 7, 2009, at 4:59 PM, fabricio wrote: > > > > > > > > > typedef subgraph< adjacency_list > Graph; > > > > > Graph G; > > > > > what I want is to create a: > > > > > vector< Graph& > subG; > > > > > but the usage of & here is illegal. > > > > Why not use pointers? > > vector subG; > > or > > vector< boost::shared_ptr > subG; > > _______________________________________________ > > Boost-users mailing list > > Boost- > us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost- > users > _______________________________________________ > Boost-users mailing list > Boost-users@lists.boost.org > http://lists.boost.org/mailman/listinfo.cgi/boost-users * Scanned by MailMarshal - Marshal's comprehensive email content security solution. Download a free evaluation of MailMarshal at www.marshal.com *
Ok, but it still won't work for me.
Let me rephrase my problem:
I have a certain Graph g and I must create several subgraphs from it.
In order to create a subgraph I must declare:
typedef subgraph
Agree with James, shared_ptr can help here...
typedef subgraph
Graph; typedef shared_ptr<Graph> GraphPtr; typedef vector<GraphPtr> Graphs; Graphs graphs; graphs.push_back(GraphPtr(new Graph));
or perhaps
Graphs graphs; graphs.resize(2);
graphs[1].reset(new Graph); graphs[1]->DoStuff();
graphs[0] = GraphPtr(new Graph); graphs[0]->DoStuff();
~Damian();
-----Original Message----- From: boost-users-boun...@lists.boost.org [mailto:boost-users- boun...@lists.boost.org] On Behalf Of fabricio Sent: Wednesday, 8 April 2009 2:54 p.m. To: boost-us...@lists.boost.org Subject: Re: [Boost-users] a vector of subgraphs
oh sorry, forgot to mention, after
vector< Graph& > subG;
I should have something like:
subG.resize(2); subG(0) = G.subgraph();
and subgraph() returns a Graph&
On 7 abr, 21:04, "James C. Sutherland"
wrote: On Apr 7, 2009, at 4:59 PM, fabricio wrote:
typedef subgraph< adjacency_list > Graph;
Graph G;
what I want is to create a:
vector< Graph& > subG;
but the usage of & here is illegal.
Why not use pointers? vector
subG; or vector< boost::shared_ptr<Graph> > subG; _______________________________________________ Boost-users mailing list Boost- us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost- users
Boost-users mailing list Boost-us...@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
* Scanned by MailMarshal - Marshal's comprehensive email content security solution. Download a free evaluation of MailMarshal atwww.marshal.com* _______________________________________________ Boost-users mailing list Boost-us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users
Pointers should still work. See below. You cannot (currently) hold references in containers. I think that this is slated to change in the new c++ standard, but don't know much about that... On Apr 8, 2009, at 8:53 AM, fabricio wrote:
Ok, but it still won't work for me.
Let me rephrase my problem:
I have a certain Graph g and I must create several subgraphs from it. In order to create a subgraph I must declare:
typedef subgraph
Graph; Graph g; and to create the proper subgraphs from g it must be done:
Graph& g1 = g.subgraph();
Graph* g1 = g.subgraph();
where the subgraph method returns a Graph&.
The problem is that I must have "n" different subgraphs and I must have a way to iterate through them. So ideally I should have:
vector< Graph& > subg;
vector< Graph* > subg;
subg.resize(n); for (i=0;i
I guess the use of the reference is necessary so when I insert an edge on one of the graphs it reflects on every subgraph.
best regards, Fabricio
On 8 abr, 00:57, "Damian Coventry"
wrote: Agree with James, shared_ptr can help here...
typedef subgraph
Graph; typedef shared_ptr<Graph> GraphPtr; typedef vector<GraphPtr> Graphs; Graphs graphs; graphs.push_back(GraphPtr(new Graph));
or perhaps
Graphs graphs; graphs.resize(2);
graphs[1].reset(new Graph); graphs[1]->DoStuff();
graphs[0] = GraphPtr(new Graph); graphs[0]->DoStuff();
~Damian();
-----Original Message----- From: boost-users-boun...@lists.boost.org [mailto:boost-users- boun...@lists.boost.org] On Behalf Of fabricio Sent: Wednesday, 8 April 2009 2:54 p.m. To: boost-us...@lists.boost.org Subject: Re: [Boost-users] a vector of subgraphs
oh sorry, forgot to mention, after
vector< Graph& > subG;
I should have something like:
subG.resize(2); subG(0) = G.subgraph();
and subgraph() returns a Graph&
On 7 abr, 21:04, "James C. Sutherland"
wrote: On Apr 7, 2009, at 4:59 PM, fabricio wrote:
typedef subgraph< adjacency_list > Graph;
Graph G;
what I want is to create a:
vector< Graph& > subG;
but the usage of & here is illegal.
Why not use pointers? vector
subG; or vector< boost::shared_ptr<Graph> > subG; _______________________________________________ Boost-users mailing list Boost- us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost- users
Boost-users mailing list Boost-us...@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
* Scanned by MailMarshal - Marshal's comprehensive email content security solution. Download a free evaluation of MailMarshal atwww.marshal.com* _______________________________________________ Boost-users mailing list Boost-us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, thanks for the answers, but using Graph* does not work, it is an
invalid cast from Graph& to Graph*
the Visual C++ gives me a C2440 error (type cast error) when I try to
make
Graph* g1 = g.subgraph();
even doing
Graph* g1 = (Graph*) g.subgraph();
On 8 abr, 14:19, "James C. Sutherland"
Pointers should still work. See below. You cannot (currently) hold references in containers. I think that this is slated to change in the new c++ standard, but don't know much about that...
On Apr 8, 2009, at 8:53 AM, fabricio wrote:
Ok, but it still won't work for me.
Let me rephrase my problem:
I have a certain Graph g and I must create several subgraphs from it. In order to create a subgraph I must declare:
typedef subgraph
Graph; Graph g; and to create the proper subgraphs from g it must be done:
Graph& g1 = g.subgraph();
Graph* g1 = g.subgraph();
where the subgraph method returns a Graph&.
The problem is that I must have "n" different subgraphs and I must have a way to iterate through them. So ideally I should have:
vector< Graph& > subg;
vector< Graph* > subg;
subg.resize(n); for (i=0;i
I guess the use of the reference is necessary so when I insert an edge on one of the graphs it reflects on every subgraph.
best regards, Fabricio
On 8 abr, 00:57, "Damian Coventry"
wrote: Agree with James, shared_ptr can help here...
typedef subgraph
Graph; typedef shared_ptr<Graph> GraphPtr; typedef vector<GraphPtr> Graphs; Graphs graphs; graphs.push_back(GraphPtr(new Graph));
or perhaps
Graphs graphs; graphs.resize(2);
graphs[1].reset(new Graph); graphs[1]->DoStuff();
graphs[0] = GraphPtr(new Graph); graphs[0]->DoStuff();
~Damian();
-----Original Message----- From: boost-users-boun...@lists.boost.org [mailto:boost-users- boun...@lists.boost.org] On Behalf Of fabricio Sent: Wednesday, 8 April 2009 2:54 p.m. To: boost-us...@lists.boost.org Subject: Re: [Boost-users] a vector of subgraphs
oh sorry, forgot to mention, after
vector< Graph& > subG;
I should have something like:
subG.resize(2); subG(0) = G.subgraph();
and subgraph() returns a Graph&
On 7 abr, 21:04, "James C. Sutherland"
wrote: On Apr 7, 2009, at 4:59 PM, fabricio wrote:
typedef subgraph< adjacency_list > Graph;
Graph G;
what I want is to create a:
vector< Graph& > subG;
but the usage of & here is illegal.
Why not use pointers? vector
subG; or vector< boost::shared_ptr<Graph> > subG; _______________________________________________ Boost-users mailing list Boost- us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost- users
Boost-users mailing list Boost-us...@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
* Scanned by MailMarshal - Marshal's comprehensive email content security solution. Download a free evaluation of MailMarshal atwww.marshal.com* _______________________________________________ Boost-users mailing list Boost-us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users mailing list Boost-us...@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users
fabricio wrote:
Hi, thanks for the answers, but using Graph* does not work, it is an invalid cast from Graph& to Graph* the Visual C++ gives me a C2440 error (type cast error) when I try to make Graph* g1 = g.subgraph();
Of course you should write Graph* g1 = &g.subgraph(); Regards, Thomas
oh how dumb of me, it solved my problem :)
thank you everyone
On 8 abr, 14:55, Thomas Klimpel
fabricio wrote:
Hi, thanks for the answers, but using Graph* does not work, it is an invalid cast from Graph& to Graph* the Visual C++ gives me a C2440 error (type cast error) when I try to make Graph* g1 = g.subgraph();
Of course you should write
Graph* g1 = &g.subgraph();
Regards, Thomas _______________________________________________ Boost-users mailing list Boost-us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Damian Coventry
-
fabricio
-
James C. Sutherland
-
Thomas Klimpel