classes and arrays

Started by
2 comments, last by Jingo 19 years, 4 months ago
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?
~guyaton
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.
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.

use std::vector.

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

This topic is closed to new replies.

Advertisement