Jump to content
  • Advertisement

Archived

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

dynamicman

Is this double pointer correct?

This topic is 6171 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

I just need to understand a bit more about double pointers... I want a pointer that points to another pointer thats an array of pointers to stuff...
    
CStuff** ppstuff;
CStuff* pstuff = new CStuff[15];
  
Then I'm not sure if I should do this...
  
ppstuff = &pstuff;
  
or...
  
(*ppstuff) = pstuff;
  
To access the array I use this...
  
ppstuff[4]->method();
  
is that correct? whould this last code access the 5th pointer in my array? [/source] Edited by - dynamicman on October 30, 2001 7:01:18 PM

Share this post


Link to post
Share on other sites
Advertisement
Well, your second assignment, (*ppstuff) = pstuff, is a recipe for disaster, since you''re basically trying to assign the value of pstuff to the memory pointed to by ppstuff--which is uninitialized.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"(*ppstuff) = pstuff, is a recipe for disaster."

Are u sure?

*ppstuff is an address(a pointer to CStuff), and dman here is assigning it with pstuff(a pointer to CStuff), also an address ''which'' he has already initilised via the statement "CStuff* pstuff = new CStuff[15];".

Dynamicman is not assigning values, but referencing addresses here.



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ppstuff is null so *ppstuff is invalid. The first form is correct. The call ppstuff[4]->method() is also correct.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!