• Advertisement

Archived

This topic is now archived and is closed to further replies.

Quick question about pointers

This topic is 5379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

void CClass::copyFrom(const CClass &rhs) { aPointer = rhs.aPointer; } does aPointer point to rhs''s aPointer or does it point to what rhs''s aPointer is pointing to? In other words if the class from which it is copying goes out of scope does the pointer become invalid?

Share this post


Link to post
Share on other sites
Advertisement
You are copying the value of the pointer, that is, its address; hence, the two pointers point to the same data.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
pPointer = pBointer; 

means that the two pointers point to the same thing.
pPointer = &pBointer; 

means that the first pointer points toward the second one.

Share this post


Link to post
Share on other sites

  • Advertisement