Clarification of when to use . , *, ->

I'm studying for a test in my c++ data structures class. I'm still a little confused about what the following operators do (book doesn't give a clear explanation) , so I was wondering if you could let me know if I have the right idea.


-> * .(dot operator)

From what I understand, -> is generally used just for dereferencing a pointer to struct ( or class ) rather than a pointer within a structure.
Whereas * dereferences the pointer regardless of what it refers to and the dot operator accesses the member of the struct/class w.o. dereference.
For example, given


1
2
3
4
5
6
7
8
9
10
struct Fluff
{
	char foo;
	int *foo2;
}



Fluff ex_Fluff;
Fluff *ptFluff;


*(ptFluff).foo should be the same as ptFluff -> foo

(They both access the contents of foo)

*((*ptFluff).foo2) should be the same as ptFluff -> *foo2

(both access contents of foo2)


exFluff.foo2 should do the same as ptFluff -> foo2

(They both access address of foo2)

(*ptFluff).foo2 should do the same as ptFluff -> foo2

(They both access address of foo2)

Is this correct? Is there anything I'm missing here in my explanation of what the operators do? Thanks for any input!
Also, first time poster, so my apologies for anything improper about the post. :]
. accesses members of an object.
* dereferences a pointer.
-> accesses members of an object pointer.

1
2
3
4
5
6
7
struct Class {
    int Member;
} Instance;
Class* PtrToInstance = &Instance;
Instance.Member = 0;
(*PtrToInstance).Member = 0;
PtrToInstance->Member = 0;


EDIT: Fixed code tags.
Last edited on
thx, i finally got this down
Topic archived. No new replies allowed.