#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>
class GraphInterface< V> :: GraphIteratorInterface {
virtual void examine_edge( /*Edge Object*/ ) = 0 ;
virtual void discover_vertex( const V & ) = 0 ;
// ...
} ;
template < class V>
class Graph< V> :: GraphIterator : public GraphInterface< V> :: GraphIteratorInterface {
std:: vector < V> vertices;
//.. other members not in the interface
void examine_edge( /*Edge Object*/ ) ;
void discover_vertex( const V & )
} ;
int main( ) {
Graph< int > g;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGU8Y2xhc3MgVj4KY2xhc3MgR3JhcGhJbnRlcmZhY2UgewoJcHVibGljOgoJLy8gQWJzdHJhY3QgR3JhcGhJdGVyYXRvciBjbGFzcywgZGVmaW5lZCBlbHNld2hlcmUKCXRlbXBsYXRlPGNsYXNzIFZFPiBjbGFzcyBHcmFwaEl0ZXJhdG9ySW50ZXJmYWNlOwoJCgl2aXJ0dWFsIH5HcmFwaEludGVyZmFjZSgpOwoJCgkvLyBCRlMgdGhhdCB1c2VzIHRoZSBncmFwaCBpdGVyYXRvciBjbGFzcyB0byBwZXJmb3JtIHdvcmsgb24gdGhlIGRpc2NvdmVyZWQKCS8vIHZlcnRpY2VzIGFuZCBlZGdlcwoJdmlydHVhbCB2b2lkIEJGUyhWIHNyY192ZXJ0ZXgsIEdyYXBoSXRlcmF0b3JJbnRlcmZhY2U8Vj4gKikgPSAwOwoJCn07Cgp0ZW1wbGF0ZTxjbGFzcyBWPgpjbGFzcyBHcmFwaCA6IHB1YmxpYyBHcmFwaEludGVyZmFjZTxWPiB7CglwdWJsaWMgOgoJdGVtcGxhdGU8Y2xhc3MgVkU+IGNsYXNzIEdyYXBoSXRlcmF0b3I7IC8vIGltcGxlbWVudHMgdGhlIGdyYXBoLWl0ZXIgaW50ZXJmYWNlCgkKCX5HcmFwaCgpOwoJCgl2b2lkIEJGUyhWIHNyY192ZXJ0ZXgsIEdyYXBoSXRlcmF0b3I8Vj4gKik7Cn07Cgp0ZW1wbGF0ZTxjbGFzcyBWPgpjbGFzcyBHcmFwaEludGVyZmFjZTxWPjo6R3JhcGhJdGVyYXRvckludGVyZmFjZSB7CgkKCXZpcnR1YWwgdm9pZCBleGFtaW5lX2VkZ2UoLypFZGdlIE9iamVjdCovKSA9IDA7Cgl2aXJ0dWFsIHZvaWQgZGlzY292ZXJfdmVydGV4KGNvbnN0IFYgJikgPSAwOwoJLy8gLi4uCn07Cgp0ZW1wbGF0ZTxjbGFzcyBWPgpjbGFzcyBHcmFwaDxWPjo6R3JhcGhJdGVyYXRvciA6IHB1YmxpYyBHcmFwaEludGVyZmFjZTxWPjo6R3JhcGhJdGVyYXRvckludGVyZmFjZSB7CglzdGQ6OnZlY3RvcjxWPiB2ZXJ0aWNlczsKCS8vLi4gb3RoZXIgbWVtYmVycyBub3QgaW4gdGhlIGludGVyZmFjZQoJdm9pZCBleGFtaW5lX2VkZ2UoLypFZGdlIE9iamVjdCovKTsKCXZvaWQgZGlzY292ZXJfdmVydGV4KGNvbnN0IFYgJikKfTsKCmludCBtYWluKCkgewoJR3JhcGg8aW50PiBnOwoJcmV0dXJuIDA7Cn0=
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