C++ Tree Interface
#include "Node.h"
// Bridge class that describes the Tree edges and
// acts as a Factory.
class Tree {
public:
// Factory operations
Tree (int);
Tree (const string &, Tree &);
Tree (const string &, Tree &, Tree &);
Tree (const Tree &t);
void operator= (const Tree &t);
~Tree ();
void print (std::ostream &) const;
private:
Node *node_; // pointer to a rooted subtree
C++ Node Interface
class Tree; // Forward declaration
// Describes the Tree vertices
class Node {
friend class Tree;
protected: // Only visible to derived classes
Node (): use_ (1) {}
/* pure */ virtual void print (std::ostream &) const = 0;
// Important to make destructor virtual!
virtual ~Node ();
private:
int use_; // Reference counter.
};
No comments:
Post a Comment