boost graph library, default_dfs_visitor, dfs
Hi Please see the code below. class my_visitor: public default_dfs_visitor { public: my_visitor(){} void finish_vertex(Vertex u, const Graph & g); vector<Vertex> getFinishingOrder(void){return finishingOrder;} //private: vector<Vertex> finishingOrder;//stores the vertices in the finishing order }; template<typename Vertex, typename Graph> void my_visitor::finish_vertex(Vertex u, const Graph & g){ finishingOrder.push_back(u); } main.cpp has the following: my_visitor vis; depth_first_search(g, visitor(vis));//to get the finishing order on vertices cout << "size of fin vector = " << vis.finishingOrder.size() << endl; 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... Does I miss something in the understanding of the visitor concept? Thanks suresh
Hi!
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...
All visitors have to be copy constructible and depth_first_search will operate on the copied object. Gabe
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...
All visitors have to be copy constructible and depth_first_search will operate on the copied object.
Actually, it's the fact that the visitor is copied that's causing the problem. The visitor needs to declare it's vector member as a reference (to a vector declared somewhere else). For example: struct my_visitor : default_dfs_visitor { my_visitor(vector<Vertex>& order) : finishingOrder(order) { } vector<Vertex>& finishingOrder; }; Andrew Sutton andrew.n.sutton@gmail.com
I understood, thanks Andrew Sutton, suresh On Wed, Dec 16, 2009 at 5:52 AM, Andrew Sutton <andrew.n.sutton@gmail.com> wrote:
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...
All visitors have to be copy constructible and depth_first_search will operate on the copied object.
Actually, it's the fact that the visitor is copied that's causing the problem. The visitor needs to declare it's vector member as a reference (to a vector declared somewhere else). For example:
struct my_visitor : default_dfs_visitor { my_visitor(vector<Vertex>& order) : finishingOrder(order) { } vector<Vertex>& finishingOrder; };
Andrew Sutton andrew.n.sutton@gmail.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org 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
participants (4)
-
Andrew Sutton
-
Gábor Szuromi
-
List User
-
Suresh Kumar