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?