< Previous | Contents | Next >

Calling Member Functions

Next, I again put the critters through their paces. I get the first critter to give a greeting.

crit1.Greet();

The preceding code calls crit1s Greet() member function. The function accesses the calling objects m_Hunger data member to form the greeting it displays. Because crit1s 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 crit2s Greet() member function. This function accesses the calling objects m_Hunger data member to form the greeting it displays. Because crit2s m_Hunger data member is 3, the function displays the text: Hi. I’m a critter. My hunger level is 3.