This is the node for a tree
class Node {
public:
string name;
map<string, string> attribute;
Node* parent;
set<Node*, customComparison> children;
};
Where customComparison
in the line set<Node*, customComparison> children
is a custom < operator I'm trying to define for Node*
objects for use in the set data structure, that orders Node*
objects according to their name data member (which is a string, using lexicographical order).
If I try to define the custom < before the class, it requires Node*
as parameters and Node isn't defined yet. If I try to define the custom < after the class, set<Node*, customComparison>
wont work because customComparison hasn't been defined yet.
It feels like what I want is self referential, because defining customComparison requires the Node class to be already fully defined, but defining the Node class requires customComparison in the first place. Is it impossible to do this? If there's a way, please show how thanks.