fork(4) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template<class V>
  6. class GraphInterface {
  7. public:
  8. // Abstract GraphIterator class, defined elsewhere
  9. template<class VE> class GraphIteratorInterface;
  10.  
  11. virtual ~GraphInterface();
  12.  
  13. // BFS that uses the graph iterator class to perform work on the discovered
  14. // vertices and edges
  15. virtual void BFS(V src_vertex, GraphIteratorInterface<V> *) = 0;
  16.  
  17. };
  18.  
  19. template<class V>
  20. class Graph : public GraphInterface<V> {
  21. public :
  22. template<class VE> class GraphIterator; // implements the graph-iter interface
  23.  
  24. ~Graph();
  25.  
  26. void BFS(V src_vertex, GraphIterator<V> *);
  27. };
  28.  
  29. template<class V>
  30. class GraphInterface<V>::GraphIteratorInterface {
  31.  
  32. virtual void examine_edge(/*Edge Object*/) = 0;
  33. virtual void discover_vertex(const V &) = 0;
  34. // ...
  35. };
  36.  
  37. template<class V>
  38. class Graph<V>::GraphIterator : public GraphInterface<V>::GraphIteratorInterface {
  39. std::vector<V> vertices;
  40. //.. other members not in the interface
  41. void examine_edge(/*Edge Object*/);
  42. void discover_vertex(const V &)
  43. };
  44.  
  45. int main() {
  46. Graph<int> g;
  47. return 0;
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:30:26: error: too few template-parameter-lists
 class GraphInterface<V>::GraphIteratorInterface {
                          ^
prog.cpp:38:17: error: too few template-parameter-lists
 class Graph<V>::GraphIterator : public GraphInterface<V>::GraphIteratorInterface {
                 ^
prog.cpp: In function ‘int main()’:
prog.cpp:46:13: error: cannot declare variable ‘g’ to be of abstract type ‘Graph<int>’
  Graph<int> g;
             ^
prog.cpp:20:7: note:   because the following virtual functions are pure within ‘Graph<int>’:
 class Graph : public GraphInterface<V> {
       ^
prog.cpp:15:15: note: 	void GraphInterface<V>::BFS(V, GraphInterface<V>::GraphIteratorInterface<V>*) [with V = int]
  virtual void BFS(V src_vertex, GraphIteratorInterface<V> *) = 0;
               ^
stdout
Standard output is empty