Note that oil_tanks[7]
refers to the eighth cylinder
object
in the oil_tanks
array (the first being indexed by 0). Similarly,
oil_tank_pointers[7]
refers to the eighth pointer in the
oil_tank_pointers
array.
To refer to the cylinder
object indexed by the value of a variable,
limit
, in the oil_tanks
array, you write
oil_tanks[limit]
; to refer to the radius of that cylinder
object, you write oil_tanks[limit].radius
.
When you work with an array of pointers to cylinder
objects,
you need to dereference a pointer when you want to refer to a
cylinder
object. Hence, *oil_tank_pointers[7]
refers to the
cylinder
object pointed to by the eighth pointer in an array. To
refer to the eighth cylinder
object's radius, you can add
.radius
, producing the following expression, which is baroque
looking, inasmuch as it has parentheses, an asterisk, brackets, and a
period:
(*oil_tank_pointers[7]).radius
Alternatively, and preferably, you can combine dereferencing and
member selection using the class-pointer operator, ->
:
oil_tank_pointers[7] -> radius