Is this double pointer correct?

Started by
2 comments, last by dynamicman 22 years, 5 months ago
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
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.
"(*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.



ppstuff is null so *ppstuff is invalid. The first form is correct. The call ppstuff[4]->method() is also correct.

This topic is closed to new replies.

Advertisement