Skip to main content
gamedev.net
🔒 Locked

Unitialized pointer

Started by KrAkPiPeR Jun 13, 2002 at 1:45 PM 3 replies 450+ views
Original Post
KrAkPiPeR
KrAkPiPeR
I am using MFC VC++ 6 and what i am trying to do is this: public: typedef struct { GLfloat x,y,z; GLint color; GLfloat u, v; } VERTEX; Declare a struct in the header file. Then, declare a pointer of type VERTEX in the same header file as in: VERTEX *Vertices; However, when i try to access this pointer (in the same class .cpp file), its address is not there. Why? [edited by - KrAkPiPeR on June 13, 2002 2:48:19 PM]
Mathematix
Mathematix
You haven''t made an attempt to initilise the pointer in any way whatsoever. Do something like

Vertices = new VERTEX;

You should find that memory has been allocated and you can now use the pointer.

Regards,
Mathematix.
uNiQue0815
uNiQue0815
it''s not really about that topic, but good discussion about valid/invalid pointers in thread : ''NULL?''
-------------------------------------------------------------

and now some on-topic...
you should maybe initialize every pointer you declare with :

anytype* pointer = NULL;

it''s not really necessary but it''s good style and makes checking, if a pointer is valid or not much easier (sometimes also makes debugging easier).

or think of the case, that the value that ''pointer'' (pseudo-)randomly gets in the beginning already is a valid pointer... if you got buggy code that doesn''t initialize the pointer but accesses the memory (as in your code above), you''ll most likely get weird results & debugging will maybe be a lot harder than it would be with all invalid pointers set to NULL...

just an advice !
Solo
Solo
quote:

However, when i try to access this pointer (in the same class .cpp file), its address is not there. Why


What do you mean when you say "in the same class .cpp file"?

Defining a variable in a header file like that is usually not a good idea. If you include the header file in more than one of your projects .cpp files you''ll get linker errors.
// Ryan
KrAkPiPeR
KrAkPiPeR
Thanks for the suggestions guys and gals, but i found that it was just one of retarded errors that i always seem to miss. You know, the obvious ones. ]
Sorry everyone.

Topic Locked

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

Sign in to reply to this topic.