Home Segments Index Top Previous Next

418: Mainline

Given that *cptr's value is a cylinder object, you can embed *cptr in larger expressions, involving the class-member operator, that retrieve member-variable values. The following, for example, retrieves the radius of a cylinder:


Note that you must enclose *cptr in parentheses to refer the radius of the cylinder object to which cptr points, because the class-member operator, the period, has precedence higher than that of the dereferencing operator, the asterisk. Accordingly, a version without parentheses, *cptr.radius, is equivalent to *(cptr.radius), which means produce the object pointed to by a pointer stored, peculiarly, in the radius member variable of a pointer to a cylinder object. What you want, of course, is the version that means produce the value stored in the radius member variable of the dereferenced pointer to a cylinder object.