tags:

views:

answers:

in this book i have I'm learning pointers, and i just got done with the chapter about OOP (spits on ground) anyways its telling me i can use a member selection operator like this ( -> ). it sayd that is is like the "." except points to objects rather than member objects. whats the difference, it looks like it is used the same way...

When you have an object instance (MyObject object;), you use the . to access it members (methods, properties, fields, etc), like this: object.Member.

When you have a pointer to an object instance (MyObject* pObject = new MyObject();), you need to dereference the pointer, before you can access the object members. To dereference a pointer you use the * operator. Thus, when you combine both, you get something like this: (*pObject).Member.

Of course, this is not readable, so the compilers take the -> as a shorthand for it. Thus, it becomes pObject->Member.