I had some time at work so here's an analogy I thought up that might help, maybe, possibly....
Suppose all the houses on the block of a street were exactly the same construction, meaning they all had a kitchen, a great room, a bathroom and two bedrooms, all with the same floor plan. They were all white and had none of them had shutters or other distinquishing features, externally. In fact even the contents of the house were the same, and includes only a single telephone with an answering machine. In fact the only differences were the address each house had and the family that lived there. Some families had both a mother and a father, some just one or the other. Some had children, some didn't, but at most there could be up to 4 children, because it's only a two bedroom house. Then pretend you can't tell what type of family lives in any given house until you look inside. You're a census taker who needs to determine what type of family lives where. Turns out there are two ways to find out how many people live in the house. You can knock on each door personally, or you can call on the phone by looking up each address in phone directory. Or call up the first phone and listen to the address stored on the answering machine to get the next address.
Using this analogy, each house is a node. Each node has one data member, an instance of a class called Family, and each Family can have at most one mother, at most one father, both of which are of type bool, and one group of kids which is an array of 4 ints, representing the age of any given child. The phone is a pointer and the answering machine is pointer to the next node in a list of houses stored in the node. The phone directory is an array of phones, that isn't used accept to except to extend the analagy a little.
Here's the classes to model the situation:
Code:
struct Family
{
Family() : mother(false), father(false)
{
int i;
for(i = 0; i < 4; ++i)
child[i] = 0;
}
bool mother;
bool father;
int child[4];
};
class house
{
public:
Family family;
long * nextHouse;//a phone
};
If you knock on the door you use the dot operator to find the information, like this:
//Declare a house:
house Smith;
//fill in family data
Smith.family.mother = true;
Smith.family.father = false;
Smith.family.child[0] = 2;
if you call on the phone you use the arrow operator like this:
//declare a phone to a house
house * SmithPhone = &Smith;
cout << SmithPhone->family.child[0];
and to call each family on the block one at a time starting from the first phone in the list you go:
Code:
while (phone->nextHouse != NULL)
{
if(phone->family.mother)
cout << "mother" << endl;
if(phone->family.father)
cout << "mother" << endl;
int i, children = 0;
for(i = 0; i < 4; ++i)
{
if(phone->family.child[i] != 0)
++children;
}
cout << "and " << children + 1 << " children, ages " << endl;
for(i = 0; i < children; ++i)
cout << phone->family.child[i] << ' ';
phone = phone->nextHouse;
}