Class and object

If I:
Person a{"p1", 'M'};
Person b{"p2", 'M'};
a.marryTo(&b);

how can I do "b.marryTo(&a);" inside the marryTo function?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Person
{
public:
Person::Person(string n, char g) :Name{ n }, Gender{ g }
{
	Father = NULL;
	Mother = NULL;
	Husband = NULL;
	Wife = NULL;
	firstChild = NULL;
	elderSibling = NULL;
	youngerSibling = NULL;

	numberChildren = 0;
}

void Person::marryTo(Person* p)
{
	if (Gender == 'M')
	{
		Wife = p;
	}
		
	if (Gender == 'F')
	{
		Husband = p;
	}	
}

private:
	std::string Name;
	char Gender;
	Person* Father; 
	Person* Mother;
	Person* Husband;
	Person* Wife;
	Person* firstChild;
	Person* elderSibling;
	Person* youngerSibling;

	int numberChildren;
};
}
Last edited on
Your data structure for a family tree isn't quite right. So starting from where you are is just gonna get more complicated.

The family tree itself is an object. I contains a network of linked persons. A person simply exists, but it's inserted into the family tree.

But you don't have a family tree object, you're trying to represent the free within Person, and now finding it's not such an easy thing to do. No one can do it, not just you.
Topic archived. No new replies allowed.