Original Post
🔒 Locked
Multiple pointers to a class
Advertisement
Try this:
Splatta *s[10];
// or Splatta **s = new Splatta*[10];
for( int n = 0; n < 10; n++ )
{
s[n] = new Splatta;
}
Splatta *s[10];
// or Splatta **s = new Splatta*[10];
for( int n = 0; n < 10; n++ )
{
s[n] = new Splatta;
}
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.
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement