Hello Robson and all Dev-C++ users,
Saturday, February 22, 2003, 4:28:53 PM, Robson wrote as follows:
RB> Hi! I'm in trouble again! My c++ book does not explain how to redim an array
RB> at run time, preserving contents.
RB> I want to resize an array of sprites every time that user presses 'N' key,
RB> to add a new sprite, specified in the following class:
RB> class SPRITE {
RB> public:
RB> int x;
RB> int y;
RB> int sx;
RB> int sy;
RB> long color;
RB> void move(void);
RB> void draw(void);
RB> void erase(void);
RB> };
RB> Any input appreciated.
IMO you should use std:vector...
just do it like this:
#include <vector>
using std::vector;
vector<SPRITE>mySprites;
//and now to add new sprite
SPRITE new;
//here make some adjustments to new object
mySprites.push_back( new );
//to get number of sprites
int count = mySprites.size();
//to get sprite number X
int x = 3;
SPRITE &duck = mySprites[ x ];
it is easy as that!
--
regards, Zodiaq
|