Accessing a pointer object member variable
Hello,
I am wondering what is the difference between
ptr->age = 11;
and
(*ptr).age = 11;
using the class
class person
{
public:
int age = 8;
int gender;
};
One will wear out your dash key faster, the other will wear our your 8, 9, and 0 keys faster.
As LB said, the only difference is what keys you press. Standard defines one in terms of other:
The expression E1->E2 is converted to the equivalent form (*(E1)).E2; |
Last edited on
Topic archived. No new replies allowed.