Skip to main content
gamedev.net
🔒 Locked

Pointer to Pointer problem

Started by saravananps Aug 23, 2006 at 12:33 AM 3 replies 400+ views
Original Post
saravananps
saravananps
Hi, i'm using vc++ 6. i've created a pointer to a class named CPolygon *pPolygon and i stored values to it. Then i created a pointer to a pointer named CPolygon **ppPolygon and i stored the address of pPolygon to it *ppPolygon = pPolygon; In the debug mode i found that ppPolygon contains the address of pPolygon. i found that first value of ppPolygon is the same as pPolygon but the remaining values are not. Could any one help me to find a solution
MrAccident
MrAccident
Yes indeedy. Just to clarify on what Mr. AP said, if you're doing something like this:
CPolygon **ppPolygon;*ppPolygon = pPolygon;
That is very bad. What you're doing in that second line is trying to dereference the pointer ppPolygon, when it hasn't even been assigned a value. This will almost certainly result in a segfault, as ppPolygon will have some invalid value, probably NULL or 0xCDCDCDCD or something like that.

In any case, that line (*ppPolygon = pPolygon) is not storing the address of pPolygon and storing it in ppPolygon: it is taking the value of pPolygon and storing it in the location that ppPolygon points to, which as I noted before, will not be a valid memory location.
Zahlman
Zahlman
0) Like they said.
1) This could reasonably go in For Beginners.
2) Just say no to VC++6. Get yourself something at least half-decently modern and up to the current language spec. There are *several, free* options for doing so, so there's really no excuse.
3) There's probably no good reason for explicitly creating a pointer to a pointer to a Polygon. What are you trying to do?
MaulingMonkey
MaulingMonkey
Quote:
Original post by Zahlman
2) Just say no to VC++6. Get yourself something at least half-decently modern and up to the current language spec. There are *several, free* options for doing so, so there's really no excuse.


*cough* Including Visual Studio 2005 Express, free (legally!) from Microsoft. *cough*

Same product, only made after there actualy was a C++ standard at all to comply with. Something I can call a C++ compiler without feeling like I'm lying.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.