... specify the object’s name (myAccount), followed by the dot operator (.), then the member function name (getName) and a set of parentheses. The empty parentheses indicate that getName does not require any additional information to perform its task. Soon, you’ll see that the setName function requires additional information to perform its task.
From main’s view, when the getName member function is called:
The program transfers execution from the call (line 13 in
main) to member functiongetName. BecausegetNamewas called via themyAccountobject,getName“knows” which object’s data to manipulate.Next, member function
getNameperforms its task—that is, it returns (i.e., gives back)myAccount’s name to line 13 where the function was called. The main ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access