class Node

This is a discussion on class Node within the C++ Programming forums, part of the General Programming Boards category; Hi all! I'm writing a "family tree"program. there's a function in my class Node which is named SON. it gets ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    35

    Question class Node

    Hi all!
    I'm writing a "family tree"program. there's a function in my class Node which is named SON. it gets 2 strings as arguments (they represent the name of the son and the father to be related respectively). I've got a problem here. if you look at the code below:
    Code:
    class Node
    {
        Node *father;
        Node *son;
        string name;
        vector<Node *> kid;
    
    
    void ADD(string s)
    	{
    		Node *n= new Node;
    		n->name=s;
    		nom.push_back(n);
    	}
    
    void SON(string s, string f)
    	{
    		for(int i=0 ; i<nom.size() ; i++)
    			{
    				if(nom[i]->name==f)
    					father=nom[i];
    				if (nom[i]->name==s)
    					son=nom[i];
    			}
    		father->kid.push_back(son);
    		son->father=father;
    
    
    	}
    };
    Does it make sense to do so? doesn't function SON, mix up the father and son with the one in the outer scope?

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    Quote Originally Posted by Farnaz View Post
    doesn't function SON, mix up the father and son with the one in the outer scope?
    Yeah, it does. Why are you doing this?
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    35
    the father, whose name is passed to the function, may have some other sons and this son is not necessarily the father's first son. so it has to be pushed back in a vector (kid). I should tell the son this father is his father and vice versa. what do you suggest me?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 02:48 AM
  2. template and friend class
    By black_spot1984 in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2008, 06:50 PM
  3. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 02:00 AM
  4. Need help with C++ linked list using objects
    By pityocamptes in forum C++ Programming
    Replies: 7
    Last Post: 05-03-2006, 12:12 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21