Boost logo

Boost Users :

Subject: Re: [Boost-users] is visitor object destroyed immediately after the execution of depth_first_search?
From: Suresh Kumar (suresh.amritapuri_at_[hidden])
Date: 2009-12-15 20:29:35


Hi Jeremiah Willcock,

Thanks for making it clear. I had guessed this. I only asked this qn
earlier. As there was no response, I re-phrased and asked
again...Thanks once again,
It works the way you said.
suresh

On Tue, Dec 15, 2009 at 4:57 PM, Jeremiah Willcock <jewillco_at_[hidden]> wrote:
> On Tue, 15 Dec 2009, Suresh Kumar wrote:
>
>> Hi,
>> my idea is to get the finishing order of vertices in dfs by pushing
>> the vertices in a vector and return it later through a function return
>> value from my visitor class object.
>> //code snippet
>> int main()
>> {
>> my_visitor vis;
>> depth_first_search(g, visitor(vis));
>> cout << "size of fin vector = " << vis.finishingOrder.size() << endl;
>> //i get zero here!!!
>> }
>>
>> class my_visitor: public default_dfs_visitor {
>> public:
>>       my_visitor(){}
>>       void finish_vertex(Vertex u, const Graph &
>> g){finishingOrder.push_back(u);};
>>       vector<Vertex> getFinishingOrder(void){return finishingOrder;}
>> private:
>>       vector<Vertex> finishingOrder;
>> };
>>
>> My problem: size of the finishingOrder vector is zero outside the
>> my_visitor::finish_vertex method. I checked its size inside the
>> my_visitor::finish_vertex method and its value is increasing every
>> time a vertex is finished.
>>
>> Does I miss something in the understanding of the visitor concept?
>
> Someone asked basically the same question in the thread "[Boost-users] boost
> graph library, default_dfs_visitor, dfs".  The visitor is copied by the
> algorithm, so you will need to have the finishingOrder vector be a reference
> to an externally declared vector.  Have your main program declare such a
> vector and have the visitor contain a reference member that points to it;
> then the vector will be available even after the algorithm finishes.
>
> -- Jeremiah Willcock
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
R. Suresh Kumar
PhD Student, Vislab
#216, Engineering II Bldg
University of California, Riverside,
CA 92521

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