I'm working on a simple little game that requires me to constantly create objects, and I figured the best way would be to use arrays as they are individually managed.
Here's the object class, simplified so I can actually see if it works at its base.
class Block
{
private:
SDL_Rect box;
public:
SDL_Rect* blockclip;
Block( int x, int y, int w, int h, int randomnumber );
void show();
};
Block::Block( int x, int y, int w, int h, int randomnumber )
{
box.x = x;
box.y = y;
box.w = w;
box.h = h;
blockclip = &clip[ randomnumber ];
lastblockheight = lastblockheight + box.h;
lastclip = randomnumber;
}
void Block::show()
{
apply_surface( box.x, box.y + newblockheight, blocks, screen, blockclip );
}
And I'm trying to create them as so:
Block Blocks[4];
for(int i =0;i<4;i++)
{
Blocks = Block( 164 - (clip[randomnumber].w), lastblockheight, clip[randomnumber].w, clip[randomnumber].h, randomnumber );
}
Then show them again later like this in the rendering loop:
for(int i =0;i<4;i++)
{
Blocks.show();
}
Now I can't figure out how I can actually perform this. As I'm getting a range of error messages.
error: no matching function for call to `Block::Block()
I tried using this method instead:
Block* Blocks[4];
for(int i =0;i<4;i++)
{
Blocks = new Block( 164 - (clip[randomnumber].w), lastblockheight, clip[randomnumber].w, clip[randomnumber].h, randomnumber );
}
But then I get this error message:
error: request for member `show' in `Blocks', which is of non-class type `Block*