Jump to content
  • Advertisement
Sign in to follow this  
guyaton

classes and arrays

This topic is 4895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to create an array of a class that requires two inputs into the constructor. i.e.
class C2DBitmap
{
C2DBitmap( bool bTransparentBitmap, bool bEnableTransparency )
...
};

but when i try to create that class i.e.
C2DBitmap *bitmap = new C2DBitmap[3]( true, false );

that line doesn't work? Is there soemthing I am doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
You can construct them all at once.

C2DBitmap *bitmap = new C2DBitmap[3];
bitmap[0] = new C2DBitmap( true, false );
bitmap[1] = new C2DBitmap( true, false );
bitmap[2] = new C2DBitmap( true, false );

the first new creates a new array.
the other new's create new instances of the class.

Share this post


Link to post
Share on other sites
Well I would set up a public bool and assign it true or false instead of trying to pass it into the constructor. I dont think you can set a constructor array like that.

from
C2DBitmap *bitmap = new C2DBitmap[3]( true, false );
to
C2DBitmap *bitmap = new C2DBitmap[3];
bitmap[0]->myFlag = true;
bitmap[0]->myFlag2 = false;
bitmap[1]->myFlag = true;
bitmap[1]->myFlag2 = false;
bitmap[2]->myFlag = true;
bitmap[2]->myFlag2 = false;

or use a for loop depending.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!