I have a Tree template -
Code:template<typename T> class Tree { public: //node class //nodes should have value, their parent, and all of their children //and functions to get all of those class Node { public: //when declaring a node, give it //a value and a parent value Node(T&, Node*&); ~Node(); bool isRoot(); T& getValue(); void setValue(T&); Node*& getParent(); std::vector<Node*>& getChildren(); int getNumOfChildren(); std::string toString(); std::string childrenToString(); bool operator==(const Node& other); private: T value; Node* parent; std::vector<Node*> children; }; Tree(); Tree(T&); ~Tree(); Node*& getRoot(); void add(T&, Node*&); private: //root of tree Node* dummyroot; Node* root; };
I want the isRoot() function to just be something like this -
Code:template<typename T> bool Tree<T>::Node::isRoot() {return this == root;}
When I do this, it tells me invalid use of nonstatic data member root. How can I access root without making it public? A couple random things I tried were-
this == &root
this == Tree<T>::root
I don't want to give a Tree variable for each Node because I don't think it makes sense. I want the Nodes to just be a Node with a value, parent, and children. Any help would be appreciated.



LinkBack URL
About LinkBacks


