After reading some books in c++,I know that it is better to hide the data members ,but sometimes the rule makes everything messy and terrible ! For example
The annoying thing here is that,in Tree's method,if I want to use the key of left of a Node *node, I must write: node->getLeft()->getKey() !!! Omg !!!
I also think of the alternative that just write the class Tree only, but if so, how can we use the root ?(Because we programming with new and delete,it is better to deal all with pointers,isn't it ?And if we declare
so in the methods,we can only use THIS to refer to the root . But this->...=... is not allowed ! That's another problem !
Please help me .
_______________ _
Regards
Code:
class Node{
private:
int key;
Node *left;
Node *right;
pubic:
// I have to provide a lot of method so that other class can deal with the node!!!
Node();
int getKey();
void setKey();
Node *getLeft();
Node *getRight();
//...
};
class Tree{
private:
Node *root;
public://...
};
I also think of the alternative that just write the class Tree only, but if so, how can we use the root ?(Because we programming with new and delete,it is better to deal all with pointers,isn't it ?And if we declare
Code:
class Tree{
int key;
Tree* left;
Tree* right;
//...
};
Please help me .
_______________ _
Regards
Comment