< Previous | Contents | Next >
Next, I again put the critters through their paces. I get the first critter to give a greeting.
crit1.Greet();
The preceding code calls crit1’s Greet() member function. The function accesses the calling object’s m_Hunger data member to form the greeting it displays. Because crit1’s m_Hunger data member is 9, the function displays the text: Hi. I’m a critter. My hunger level is 9.
Finally, I get the second critter to speak up.
crit2.Greet();
The preceding code calls crit2’s Greet() member function. This function accesses the calling object’s m_Hunger data member to form the greeting it displays. Because crit2’s m_Hunger data member is 3, the function displays the text: Hi. I’m a critter. My hunger level is 3.