   Having trouble creating an array of objects
  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*
  I can compile that example with a few modifications as I don't have SDL#include <iostream>class Block{private:int box;public: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 ){}void Block::show(){std::cout << "Show()\n";}int main(){Block* Blocks[4];for(int i =0;i<4;i++){Blocks = new Block( 1, 2, 3, 4, 5 );}for(int i =0;i<4;i++){Blocks->show();}return 0;}You have to use the new Block(...) method to do what you are doing. As well, you need to do Blocks->show();. Notice the -> ?//editoops, used code. Changed to source tags   ;  The problem you are having is that you have defined a constructor for Block:Block::Block( int x, int y, int w, int h, int randomnumber )but, then you are making an array of Block like so:Block Blocks[4];This is problematic since you are trying to create new Block objects with a default constructor Block(), but you have only defined the constructor that I copied above.One solution would be to define a default constructor Block(){...whatever...}.  Then just initialize the array of Block.Another solution would be to  initialize like:Block Blocks[2] = { Block( int arg1, int arg2, ... int argn) , Block( int arg1_2, int arg2_2, ... int argn_2) };This case, I think, calls for a brace-enclosed initializer list ( it compiles for me ).Maybe another solution would be to use std::vector and initialize in a for loop, for example.Just some thoughts.   ;Quote:Original post by JJJohanNow 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()That means exactly what it says: it wants to call the default constructor of Block, and such a constructor doesn't exist.If you define any constructor that takes arguments, the default constructor is suppressed. You have to add it back yourself if you want it to exist.However, it's possible to have a class that shouldn't be default-constructed ever, because there is no sane "default value" for the instances.Quote:I tried using this method instead:*** Source Snippet Removed ***But then I get this error message:error: request for member `show' in `Blocks', which is of non-class type `Block*That means exactly what it says: 'Blocks' is a pointer to a Block (because you changed 'Blocks' to be an array of pointers to Block), and you're trying to get the 'show' member function of the pointer. Pointers don't have member functions; class instances do. So you want to get at the pointed-at Block instance (i.e. "dereference" the pointer) and then call *its* 'show'. You do this, in one step, by using '->' on the pointer rather than '.'.