Ok, basicy what im trying to do is use dynamic memory to create a user defined array of a class... heres sorta what i have so far, or atleast the way iv'e tryed to go about it
defined class in header file
Code:
class SPRITE{
public:
int posx, posy;
int health;
int sprite_id;
}typedef sprite[i];
and the .cpp file
Code:
#include <iostream>
#include <new
#include "sprite.h"
using namespace std;
int main()
{
int i = 3; // create a variable
cin>> i;
sprite *enemy[i]; //Create dynamic memory
enemy[i] = new sprite;
enemy[1].posx = 3; //define a variable from the class array
cout<< enemy[1].posx; //print resualt
return 0;
}
The idea of what im trying to do is create a sprite handler that creates and many or as little sprites as needed for a level without wasting any memory.
This is the first time iv'e ever user used dynamic memory i'm not even sure if this is the best way o go about this but any advise and help would be appriciated
cheers
Matty Alan