Thread: class Node

  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
    2,739
    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, 01:48 AM
  2. template and friend class
    By black_spot1984 in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2008, 05:50 PM
  3. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 01:00 AM
  4. Need help with C++ linked list using objects
    By pityocamptes in forum C++ Programming
    Replies: 7
    Last Post: 05-03-2006, 11:12 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM