• Advertisement
Sign in to follow this  

classes and arrays

This topic is 4802 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
use std::vector.


#include<vector>

std::vector<C2DBitmap> bitmap(3, C2DBitmap(true, false));

Share this post


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

  • Advertisement