I am facing general programming related logical error. I want to access bolean variable of the class by using get method. but it is not giving the right result. When i read the counter and boolean variable by getcount() and isPathExist() methods. Each time it returns "0" for counter and false for boolean.


class DFSVisitor: public default_dfs_visitor
{
protected:
	slBayesianNetwork *pBN;
	int nodeA, nodeC;
        bool exist;
	int counter;


In the BGL, visitors are passed by value into and between internal function calls so you can't expect counter (for example) to refer to the same integer object before, during and after an algorithm.

Instead, redefine your visitor to contain references or pointers to objects where you call the algorithm. For example:

struct my_visitor : default_dfs_visitor {
  int& counter;
  visitor(int& x) : counter(x) { }
}

// When I call dfs
int count = 0;
depth_first_search(g, visitor(my_visitor(count)));
cout << count << "\n";  // prints some number > 0

Andrew Sutton
andrew.n.sutton@gmail.com