fork 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. template <class VE>
  31. class GraphInterface<V>::GraphIteratorInterface {
  32.  
  33. virtual void examine_edge(VE &) = 0;
  34. virtual void discover_vertex(const V &) = 0;
  35. // ...
  36. };
  37.  
  38. template<class V> template <class VE>
  39. class Graph<V>::GraphIterator : public GraphInterface<V>::template GraphIteratorInterface<VE> {
  40. std::vector<V> vertices;
  41. //.. other members not in the interface
  42. void examine_edge(VE &);
  43. void discover_vertex(const V &);
  44. };
  45.  
  46. int main() {
  47. Graph<int> g;
  48. return 0;
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:47: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