C++ Access members in the structure
http//:swww.theitroad.com
In C++, members of a structure can be accessed using the dot (.) operator or the arrow (->) operator, depending on whether the variable is an instance of the structure or a pointer to the structure.
To access a member of a structure using the dot operator, the syntax is as follows:
struct MyStruct { int x; int y; }; MyStruct s; s.x = 1; s.y = 2;
To access a member of a structure using the arrow operator, the syntax is as follows:
MyStruct* ps = new MyStruct; ps->x = 1; ps->y = 2;
In this case, the arrow operator is used because ps
is a pointer to a MyStruct
object, not an instance of the structure itself.