|
-
Nov 21st, 2002, 07:38 PM
#1
Thread Starter
Addicted Member
the dot and ->
I have an array of objects on the free store
Obj *myObj = new Obj[10];
when i want to access these (compiler:MSVC++), i have to say myObj[x].whatever
but if i do just one object on the free store:
Obj *myObj = new Obj;
i must say myObj->whatever
If they are both pointers, why do i have to use the dot for one and the -> for the other?
-
Nov 21st, 2002, 08:23 PM
#2
Stuck in the 80s
I don't know if this contains the answer, but a question about these too was asked not too long ago:
http://www.vbforums.com/showthread.p...hreadid=215027
-
Nov 21st, 2002, 09:43 PM
#3
Frenzied Member
You could rewrite obj->member to (*obj).member. From this, you realize that obj[x].member is a form of dereferencing.
Z.
-
Nov 22nd, 2002, 08:56 AM
#4
If you have a pointer:
Obj *ptr;
then
ptr[x]
is equivalent to writing
*(ptr+x)
So
ptr[x].elem
is equivalent to
(*(ptr+x)).elem
ptr->elem
is equivalent to
(*ptr).elem
so the only real difference is the offset x
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|