Accessing public Class Members Through Objects, References and Pointers

Consider an Account class that has a public setBalance member function. Given the following declarations:

Account account; // an Account object// accountRef refers to an Account objectAccount &accountRef = account;// accountPtr points to an Account objectAccount *accountPtr = &account;

You can invoke member function setBalance using the dot (.) and arrow (->) member selection operators as follows:

// call setBalance via the Account objectaccount.setBalance( 123.45 );// call setBalance via a reference to the Account objectaccountRef.setBalance( 123.45 );// call setBalance via a pointer to the Account objectaccountPtr->setBalance( ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.