Class and struct have only two differences in C ++. (1) The default access permission for members in class is private, while that for struct is public. (2) inherit from class is private by default, while inherit from struct is public by default. Difference between the member operator (·) and the operator pointing to the struct member (->)
Difference between the member operator (·) and the operator pointing to the struct member (->)
Both are used to reference struct variables, but their application environments are completely different. The former is used in a general struct variable, and the latter is used with pointers to struct variables. For example: defined
Struct student
{
Long num;
Float score;
};
Struct student stud, * PTR = & stud;
Then stud. num, stud. score, PTR-> num and so on are all correct references, but PTR. num and stud-> num are not allowed. In fact, PTR-> num is equivalent to (* PTR ). num, which is dedicated to providing the-> operator for the sake of being more intuitive.
It is pointed out that both of them have the highest priority and are combined from left to right.