#include <iostream>
#include <vector>
using namespace std;
template < class V>
class GraphInterface {
public :
// Abstract GraphIterator class, defined elsewhere
template < class VE> class GraphIteratorInterface;
virtual ~GraphInterface( ) ;
// BFS that uses the graph iterator class to perform work on the discovered
// vertices and edges
virtual void BFS( V src_vertex, GraphIteratorInterface< V> * ) = 0 ;
} ;
template < class V>
class Graph : public GraphInterface< V> {
public :
template < class VE> class GraphIterator; // implements the graph-iter interface
~Graph( ) ;
void BFS( V src_vertex, GraphIterator< V> * ) ;
} ;
template < class V>
template < class VE>
class GraphInterface< V> :: GraphIteratorInterface {
virtual void examine_edge( VE & ) = 0 ;
virtual void discover_vertex( const V & ) = 0 ;
// ...
} ;
template < class V> template < class VE>
class Graph< V> :: GraphIterator : public GraphInterface< V> :: template GraphIteratorInterface< VE> {
std:: vector < V> vertices;
//.. other members not in the interface
void examine_edge( VE & ) ;
void discover_vertex( const V & ) ;
} ;
int main( ) {
Graph< int > g;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGU8Y2xhc3MgVj4KY2xhc3MgR3JhcGhJbnRlcmZhY2UgewoJcHVibGljOgoJLy8gQWJzdHJhY3QgR3JhcGhJdGVyYXRvciBjbGFzcywgZGVmaW5lZCBlbHNld2hlcmUKCXRlbXBsYXRlPGNsYXNzIFZFPiBjbGFzcyBHcmFwaEl0ZXJhdG9ySW50ZXJmYWNlOwoJCgl2aXJ0dWFsIH5HcmFwaEludGVyZmFjZSgpOwoJCgkvLyBCRlMgdGhhdCB1c2VzIHRoZSBncmFwaCBpdGVyYXRvciBjbGFzcyB0byBwZXJmb3JtIHdvcmsgb24gdGhlIGRpc2NvdmVyZWQKCS8vIHZlcnRpY2VzIGFuZCBlZGdlcwoJdmlydHVhbCB2b2lkIEJGUyhWIHNyY192ZXJ0ZXgsIEdyYXBoSXRlcmF0b3JJbnRlcmZhY2U8Vj4gKikgPSAwOwoJCn07Cgp0ZW1wbGF0ZTxjbGFzcyBWPgpjbGFzcyBHcmFwaCA6IHB1YmxpYyBHcmFwaEludGVyZmFjZTxWPiB7CglwdWJsaWMgOgoJdGVtcGxhdGU8Y2xhc3MgVkU+IGNsYXNzIEdyYXBoSXRlcmF0b3I7IC8vIGltcGxlbWVudHMgdGhlIGdyYXBoLWl0ZXIgaW50ZXJmYWNlCgkKCX5HcmFwaCgpOwoJCgl2b2lkIEJGUyhWIHNyY192ZXJ0ZXgsIEdyYXBoSXRlcmF0b3I8Vj4gKik7Cn07Cgp0ZW1wbGF0ZTxjbGFzcyBWPiAKdGVtcGxhdGUgPGNsYXNzIFZFPgpjbGFzcyBHcmFwaEludGVyZmFjZTxWPjo6R3JhcGhJdGVyYXRvckludGVyZmFjZSB7CgkKCXZpcnR1YWwgdm9pZCBleGFtaW5lX2VkZ2UoVkUgJikgPSAwOwoJdmlydHVhbCB2b2lkIGRpc2NvdmVyX3ZlcnRleChjb25zdCBWICYpID0gMDsKCS8vIC4uLgp9OwoKdGVtcGxhdGU8Y2xhc3MgVj4gdGVtcGxhdGUgPGNsYXNzIFZFPgpjbGFzcyBHcmFwaDxWPjo6R3JhcGhJdGVyYXRvciA6IHB1YmxpYyBHcmFwaEludGVyZmFjZTxWPjo6dGVtcGxhdGUgR3JhcGhJdGVyYXRvckludGVyZmFjZTxWRT4gewoJc3RkOjp2ZWN0b3I8Vj4gdmVydGljZXM7CgkvLy4uIG90aGVyIG1lbWJlcnMgbm90IGluIHRoZSBpbnRlcmZhY2UKCXZvaWQgZXhhbWluZV9lZGdlKFZFICYpOwoJdm9pZCBkaXNjb3Zlcl92ZXJ0ZXgoY29uc3QgViAmKTsKfTsKCmludCBtYWluKCkgewoJR3JhcGg8aW50PiBnOwoJcmV0dXJuIDA7Cn0=
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