Thread: Newb question about tree in c++...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    9

    Newb question about tree in c++...

    Hi, I have a problem understanding how to increment the occupancy in my constructor is it looks like dis:

    Code:
    template <class Whatever>
    struct TNode {
    	long balance;
    	Whatever data;
    	long height;
    	TNode<Whatever> * left;
    	long & occupancy;
    	TNode<Whatever> * right;
    	unsigned long & tree_count;
    	
    	TNode (const Whatever & element, Tree<Whatever> & theTree)
    		: balance (0), data (element), height (0), left (0), 
    		occupancy (theTree.occupancy), right (0), 
    		tree_count (theTree.tree_count) {
                 // INCREMENT OCCUPANCY
    	}
    cuz i tried occupancy++; <- doesnt work...
    I have tried everythingt o understand... but I still do not understand how to increment the occupancy in the constructor... plz help...

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What about occupancy++ doesn't work? It should work, as long as you put it inside your constructor, and not randomly in the initialization list. You could also add the ++ to the initialization part if you tack it on to theTree.occupancy.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    9
    the error when I run the gdb (debug) says that:

    warning: Source file is more recent than executable.

    46 occupancy++;

    ...

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I believe that means that you need to rebuild the executable. When you change the code you need to build the executable again before running it.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    9
    sorry, I am confused in what that means... does that mean I need to change something in my main? or in my tree constructor?

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    No, it means you have to compile and link your code. The code is correct, your debugger is telling you that you have to re-compile the changes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. changing a tree into a list question..
    By transgalactic2 in forum C Programming
    Replies: 20
    Last Post: 11-11-2008, 08:40 AM
  2. newb question
    By C_ntua in forum C++ Programming
    Replies: 3
    Last Post: 09-25-2008, 09:44 AM
  3. Question: Binary Tree only with parent pointer
    By outlaw525 in forum C Programming
    Replies: 11
    Last Post: 06-24-2008, 05:07 PM
  4. Newb Question Character Counting
    By Wilder in forum C Programming
    Replies: 13
    Last Post: 06-22-2008, 11:37 PM
  5. Binary Search Tree - one last question
    By tms43 in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2006, 03:58 AM