原完整教程鏈接:6.12 Member selection with pointers and references
1.
struct Person
{
int age;
double weight;
};
Person person;
// Member selection using pointer to struct
Person *ptr = &person;
(*ptr).age= 5;
/*
Because the syntax for access to structs and class members
through a pointer is awkward, C++ offers a second member
selection operator (->) for doing member selection from pointers.
The following two lines are equivalent:
*/
(*ptr).age = 5;
ptr->age = 5;
****Rule: When using a pointer to access the value of a member,
use operator-> instead of operator. (the . operator)****