I have a class that implements a node in a binary tree. It is based on
http://en.wikipedia.org/wiki/Binary_search_tree and looks something like this:
class IBinaryTreeNode
{
public:
IBinaryTreeNode();
virtual int GetKey() = 0;
private:
void Add(IBinaryTreeNode* pNode);
void Remove(IBinaryTreeNode** pRoot);
void DebugDraw(int Indent, char LR);
void ReplaceWith(IBinaryTreeNode* pNode);
void RemoveAtParent(IBinaryTreeNode** pRoot, IBinaryTreeNode* pNewChild);
IBinaryTreeNode* FindRightmost();
IBinaryTreeNode* m_pParent;
IBinaryTreeNode* m_pLeft;
IBinaryTreeNode* m_pRight;
};
The idea is that any class that wants to be in a tree will derive from it and implement the GetKey() function. I also have the actual binary tree class that looks like this:
class CBinaryTree
{
public:
CBinaryTree();
void AddNode(IBinaryTreeNode *pNode);
void RemoveNode(IBinaryTreeNode *pNode);
void DebugDrawTree();
void DebugDrawAscending();
private:
IBinaryTreeNode* m_pRoot;
};
What I want to do is make only the constructor and the GetValue member functions be accessable to any classes derived from IBinaryTreeNode.
Then
void Add(IBinaryTreeNode* pNode);
void Remove(IBinaryTreeNode** pRoot);
void DebugDraw(int Indent, char LR);
is only accessable to CBinaryTree
and
void ReplaceWith(IBinaryTreeNode* pNode);
void RemoveAtParent(IBinaryTreeNode** pRoot, IBinaryTreeNode* pNewChild);
IBinaryTreeNode* FindRightmost();
IBinaryTreeNode* m_pParent;
IBinaryTreeNode* m_pLeft;
IBinaryTreeNode* m_pRight;
is private to the IBinaryTreeNode class.
Please post your suggestion for this class design
Thanks.