I have a problem, I have classes that work now, because I have a specialty in the public, but If I inherited it in private, or protected and second class, then this is not work, how can I do this? I need to respect OOP rules
template & lt; Typename T & gt; Class BinaryNode {public: T key; Binernode & lt; T & gt; * Left; Binernode & lt; T & gt; * Right; Binernode & lt; T & gt; * Guardian; Binarynode () {} ~ Binarineode () {}}; And this: Template & lt; Typename T & gt; Class BinarySearchTree {Private: Binernode & lt; T & gt; * Route; Binernode & lt; T & gt; * NewNode (T key); BinaryNode & lt; T & gt; * Minimum (binary node & lt; T & gt; * node); Binernode & lt; T & gt; * Maximum (binary node & lt; T & gt; * node); BinaryNode & lt; T & gt; * Successor (Binarineod * node); Enter zero (binary node & lt; T & gt; ** node, t key); BinaryNode & lt; T & gt; * Search (Binernode & lt; T & gt; * node, T key); Zero distance (BinaryNode & lt; T & gt; * node, T key); Zero inorderTreeWalk (BinaryNode & lt; T & gt; * node); Public: BinarySearchTree (); ~ BinarySearchTree (); Insert zero (T key); Binernode & lt; T & gt; * Search (T key); Zero distance (t key); Zero Undertworld (); BinaryNode & lt; T & gt; * Remove (BinaryNode & lt; T & gt; * node); };
The header file is:
Can you show me how I can do it? Thanks, By
You can BinarySearchTree to BinaryNode of a Friends class .
template & lt; Typename T & gt; Class binary search; // Next Announcement Template & lt; Typename T & gt; Class BinaryNode {Friend class BinarySearchTree & lt; T & gt; // We only allow BinarySearchTree with the same template t access: // you make what you want to personalize}
In this way, BinarySearchTree will be able to use the private sector Access is allowed for BinaryNode
Note that you do not need to create empty default constructor / destructors.
The following lines are not required:
BinaryNode () {} ~ BinaryNode () {}
< P> [edit: Added template logic. See for other possibilities]
Comments
Post a Comment