I have two classes:
class entity {
public:
SDL_Rect pos;
float x;
float y;
std::string spriteFile;
SDL_Surface * spriteHandle;
int rePos (int newX, int newY);
int move (float deltaX, float deltaY, bool check); // Move x & y the specified amounts, also moving pos.x and pos.y for every integer increase of x or y
int display (SDL_Surface * screenSurface); //Use SDL_BlipSurface to blip the image to the screen
int loadImage (SDL_PixelFormat * format); //Load the image using the spriteFile string and optimize it using the SDL_PixelFormat of the Screen
entity (std::string file, int w, int h);
entity () {};
~entity () { SDL_FreeSurface(spriteHandle);}
entity (const entity &old) : pos(old.pos), x(old.x), y(old.y), spriteFile(old.spriteFile) {
spriteHandle = new SDL_Surface(*spriteHandle);
}
};
class multiEntity: public entity {
/*
Use multiEntity rather than entity when multiple images need to be blipped to different
positions.
*/
private:
static std::vector<stringBoolPair> deconstructed;
public:
std::string entType;
multiEntity (std::string file, int w, int h, std::string enttype) {
entity(file, w, h);
entType = enttype;
bool found = false;
for (int i = 0; i < deconstructed.size(); i++) {
found = (enttype == deconstructed[i].str);
}
if (found) deconstructed.emplace_back(enttype, false);
}
multiEntity (const multiEntity& old) :
spriteFile(old.spriteFile),
x(old.x),
y(old.y),
spriteHandle(old.spriteHandle),
pos(old.pos),
entType(old.entType) {}
~multiEntity () {
for (int i = 0; i < deconstructed.size(); i++) {
if (deconstructed[i].str == entType) {
SDL_FreeSurface(spriteHandle);
deconstructed[i].Bool = true;
}
}
}
multiEntity& operator= (const multiEntity& old) {
spriteFile = old.spriteFile;
pos = old.pos;
x = old.x;
y = old.y;
entType = old.entType;
spriteHandle = old.spriteHandle;
return *this;
}
};
When I attempt to compile the code that includes this, I get an error messages saying that class multiEntity does not have any field named 'pos'. This happens for all of the variables in the copy constructor except for entType.
What I'm attempting to do is have a vector of entitys using the same SDL_Surface. Therefore, I felt that I should create a separate class where every object with the same entType has the same value for spriteHandle. This is supposed to point to the same image, which is most useful when I have 75 instances of an image that I'm trying to blip to the screen. I want to use vector's constructor layout so that the information is copied over rather than creating a new pointer each time.