August 2001
Beginner
482 pages
10h 52m
English
You accessed data members and functions by using the dot (.) operator for Cat objects created locally. To access the Cat object on the heap, you must dereference the pointer and call the dot operator on the object pointed to by the pointer. Therefore, to access the GetAge member function, you would write
(*pRags).GetAge();
Parentheses are used to assure that pRags is dereferenced before GetAge() is accessed.
Because this is cumbersome, C++ provides a shorthand operator for indirect access: the points-to operator (->), which is created by typing the dash (-) immediately followed by the greater-than symbol (>). C++ treats this as a single symbol. Listing 10.2 demonstrates accessing member variables and functions ...
Read now
Unlock full access