Hi guys,
I have one rather strange compilation problem up my sleaves (error: redefinition of ‘class SpriteSheet’)…
I have a class named ‘SpriteSheet’ which is declared in a header file like so:
#include <SDL/SDL.h>
#include <string>
using namespace std;
class SpriteSheet {
private:
SDL_Surface *surface;
int number_rows;
int number_cols;
SDL_Rect *bounds_array;
public:
SpriteSheet(string, int, int);
// Deconstructor needed to delete dynamic stuff
~SpriteSheet();
SDL_Surface* get_SpriteSheet();
SDL_Rect* get_bounds(int);
};
and a inplymentation CPP file:
#include <SDL/SDL.h>
#include <string>
#include "SDL_Utilities.h"
#include "SpriteSheet.h"
using namespace std;
SpriteSheet::SpriteSheet(string filename, int rows, int cols) {
surface = load_image(filename.c_str());
bounds_array = new SDL_Rect[cols * rows];
int width_of_single_frame = surface->w / cols;
int height_of_single_frame = surface->h / rows;
for (int y = 0; y < number_rows; y++) {
for (int x = 0; x < number_cols; x++) {
SDL_Rect element_bounds;
element_bounds.x = x * width_of_siingle_frame;
element_bounds.y = y * height_of_single_frame;
element_bounds.w = width_of_single_frame;
element_bounds.h = height_of_single_frame;
bounds_array[y * number_rows + x] = element_bounds;
}
}
number_rows = rows;
number_cols = cols;
}
SpriteSheet::~SpriteSheet() {
SDL_FreeSurface(surface);
delete bounds_array[i];
}
SDL_Surface* SpriteSheet::get_SpriteSheet() {
return surface;
}
SDL_Rect* SpriteSheet::get_bounds(int x) {
// Temp
int y = 0;
return &bounds_array[y * number_rows + x];
}
I have checked everywhere with the find funcction in the IDE and i cannot find any other definitions of the class, so i don`t know what the compiler is talking about?
Thanks, PraiseWheat