Thread: Binary Tree header file

  1. #1
    Registered User
    Join Date
    Oct 2011

    Binary Tree header file

    I am creating a binary tree header file, but only using class (not struct). This is what I have but I get an error and I don't understand how to fix it. Error:
    Main.cpp: In function `int main(int, char **)':

    BinaryTree.h:21: `class binaryTree::node * binaryTree::root' is private
    Main.cpp:12: within this context
    BinaryTree.h:21: `class binaryTree::node * binaryTree::root' is private
    Main.cpp:15: within this context

    using namespace std;
    #ifndef BINARYTREE_H
    #define BINARYTREE_H
    class binaryTree
         class node
            int data;
            node *left;
            node *right;
            void addNode(int key, node *n);
      node *root; // the root
      void inorder(node *n);
       void binaryTree::addNode(int key, node *n);
      void addNode(int key);
      int getHeight(node *n);
      node getRoot();
      binaryTree(int data);

  2. #2
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Showing us Main.cpp would probably be a good first step

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    It appears that you're trying to use root from main instead of calling getRoot() like you're supposed to.
    However getRoot is a little broken at the moment. It needs to return a pointer.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Tree and File I/O
    By Matus in forum C Programming
    Replies: 24
    Last Post: 12-05-2008, 12:41 PM
  2. Changing header data in binary file
    By neruocomp in forum C Programming
    Replies: 8
    Last Post: 11-14-2008, 07:30 PM
  3. Replies: 1
    Last Post: 04-26-2008, 07:04 PM
  4. Binary Tree - Reading From and Writing to a File
    By Ctank02 in forum C++ Programming
    Replies: 2
    Last Post: 03-15-2008, 09:22 PM
  5. Representing a tree structure in a binary file
    By Shamino in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2006, 09:29 AM