Sign in to follow this  

classes and arrays

This topic is 4732 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
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

This topic is 4732 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this