|
-
Nov 25th, 2002, 06:12 PM
#1
Thread Starter
Addicted Member
Creating a pointer to one element in an array
I have an array of objects:
Obj *ObjectDatabase = new Obj[10];
Obj *curObject;
At some point, i want to make curObject point to a single Obj in the array, like curObject = myObject[2], only that doesn't work.
please let me know how to do this.
thanks
-
Nov 25th, 2002, 06:30 PM
#2
The [] operator automatically derefences.
You can do
curObject = &ObjectDatabase[2];
or (I prefer it, although it is harder to read for a newbie)
curObject = ObjectDatabase+2;
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
|