Not able to new element in a Dynamiclly Created array

Hi Guys,

Sorry too keep posting on these forums but… Hey that`s what there are for… Or are they?

Anyway ive got this problem with a class that ive created called ToolbarSprite. I`ve declared a pointer in a header file (Toobar) like this:

ToolbarSprites *toolbar_tiles;

and referenced it in the Toolbar sprites constructor:

toolbar_tiles = new ToolbarSprite[36]; // Comes up with "error: no matching function for call to ToolbarSprite(int, int, int)" ??? I`m not trying to initalize a contructor all i`m trying to do it tell the compiler how many elements i want

and ive got a for loop that comes up with the error "no match for operator= in *(((Toolbar*)this)->Toolbar::toolbar_tiles + ((unsigned int)(((uns... " heres the code:

for (int i = 0; i < 36; i++)  {
    toolbar_tiles[i] = new ToolbarSprite(//STUFF IN HERE)
}

Any ideas on how I could fix this?

Thanks. Mr Wheat

If you want to create an array of pointers you should consider doing this

ToolbarSprites *toolbar_tiles[36];

for (int i = 0; i < 36; i++)  
{ 
    toolbar_tiles[i] = new ToolbarSprite(//STUFF IN HERE) 
} 

In your code you were allocating an array of ToolbarSprites, (which calls a constructor for each element). If you wanted to create an array of pointers you should have tried:

ToolbarSprites **toolbar_tiles; // Notice the double pointer
toolbar_tiles = new ToolbarSpirtes* [36];
for (int i = 0; i < 36; i++) 
{ 
    toolbar_tiles[i] = new ToolbarSprite(//STUFF IN HERE) 
}