Skip to main content
gamedev.net
🔒 Locked

Multiple pointers to a class

Started by Afgo Mar 2, 2000 at 5:33 AM 1 replies 450+ views
Original Post
Afgo
Afgo
I have a class that I want multiple pointers to.. but I can''t get it to work.. int s; for(int i=0;i<10;i++) { Splatta *s; s[i] = new Splatta; }
Spellbound
Spellbound
Try this:

Splatta *s[10];
// or Splatta **s = new Splatta*[10];
for( int n = 0; n < 10; n++ )
{
s[n] = new Splatta;
}
Danack
Danack
I don''t know what your int s; is doing on the first line....

You need to declare s as an array of pointers rather than a single pointer ( and as its a pointer label it pS)

--------------------------------------------------

#define MAX_SPLATS 10

Splatta *pSplatta[ MAX_SPLATS ];

for( int i=0 ; i< MAX_SPLATS ; i++ )
{
pSplatta[ i ] = new Splatta;
}


---------------------------------------

or more elegantly

#define MAX_SPLATS 10

Splatta *pSplatta[];

pSplatta = new Splatta[ MAX_SPLATS ];

Here pSplatta is a pointer to an array of splats, instead of an array of pointers

If you use the array like this remember to delete it by:

delete []pSplatta;

Danack



Game production:
Good, quick, cheap: Choose two.
Game production:Good, quick, cheap: Choose two.

Topic Locked

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

Sign in to reply to this topic.