|
-
October 27th, 2010, 04:49 AM
#6
Re: Automatically obtaining the address of another member of the same object
 Originally Posted by nuzzle
It sure works. The stuff_ptr() function will always return a pointer to stuff of the current object.
What you cannot do is assign stuff_ptr() to an object variable and then copy the object. Then the variable in the copy will point to stuff of the object it was copied from. So you must always access stuff via a call to stuff_ptr() and never store a pointer to stuff in an object variable. But the same goes for Lindley's getOtherAddr() function so there's no difference really. Lindley's suggestion is just more complicated.
I missread your code, sorry. I though stuff_ptr was actually a member variable initialized to stuff. Didn't see it was actually a function.
I'm still not sure what Lindley is trying to do, so I can't judge either approach.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
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
|