template <typename Graph> class ConnectivityTesterDFS : public DFS<Graph> { // test connectivity protected: // local types typedef typename Graph::Vertex Vertex; private: int reached; // how many verts reached protected: // overriden functions virtual void startVisit(const Vertex& v) // count visited vertex { reached++; } public: ConnectivityTesterDFS(const Graph& g) // constructor : DFS<Graph>(g) { } bool run() { // main entry point initialize(); // initialize DFS reached = 0; // init vertex count if (!G.isEmpty()) { Vertex v = G.aVertex(); // select any vertex dfsTraversal(v); // start DFS here } return (reached == G.numVertices()); // visit all => connected } };