This has been bugging the hell out of me and has driven me to close my ide in frustration far too many times. I get the error that the function was not declared in the class, and another fun error 'funcname' is not a member of 'CApp'. These errors come in couples.
Here's my header and code, have at it before I throw my computer out the window
Code:
#ifndef _CAPP_H_
#define _CAPP_H_
#include <SDL.h>
#include <SDL_image.h>
class CApp {
public:
CApp();
int OnExecute();
bool OnInit();
void OnEvent(SDL_Event* Event);
void OnCleanup();
void OnRender();
static SDL_Surface* OnLoad(char* File);
static bool OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y);
static bool OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int X2, int Y2, int W, int H);
private:
bool Running;
SDL_Surface* Surf_Display;
SDL_Surface* Surf_Test;
};
#endif
Code:
#include "CApp.h"
CApp::CApp() {
Surf_Test = NULL;
Surf_Display = NULL;
Running = true;
}
bool CApp::OnInit() {
if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
return false;
}
if((Surf_Display = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) {
return false;
}
if((Surf_Test = CApp::OnLoad("myimage.bmp")) == NULL) {
return false;
}
return true;
}
bool CApp::OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int X2, int Y2, int W, int H) {
if(Surf_Dest == NULL || Surf_Src == NULL) {
return false;
}
SDL_Rect DestR;
DestR.x = X;
DestR.y = Y;
SDL_Rect SrcR;
SrcR.x = X2;
SrcR.y = Y2;
SrcR.w = W;
SrcR.h = H;
SDL_BlitSurface(Surf_Src, &SrcR, Surf_Dest, &DestR);
return true;
}
bool CApp::OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y) {
if(Surf_Dest == NULL || Surf_Src == NULL) {
return false;
}
SDL_Rect DestR;
DestR.x = X;
DestR.y = Y;
SDL_BlitSurface(Surf_Src, NULL, Surf_Dest, &DestR);
return true;
}
SDL_Surface* CApp::OnLoad(char* File) {
SDL_Surface* Surf_Temp = NULL;
SDL_Surface* Surf_Return = NULL;
if((Surf_Temp = IMG_Load(File)) == NULL) {
return NULL;
}
Surf_Return = SDL_DisplayFormat(Surf_Temp);
SDL_FreeSurface(Surf_Temp);
return Surf_Return;
}
void CApp::OnCleanup() {
SDL_FreeSurface(Surf_Test);
SDL_FreeSurface(Surf_Display);
SDL_Quit();
}
void CApp::OnRender() {
CApp::OnDraw(Surf_Display, Surf_Test, 0, 0);
CApp::OnDraw(Surf_Display, Surf_Test, 100, 100, 0, 0, 50, 50);
SDL_Flip(Surf_Display);
}
void CApp::OnEvent(SDL_Event* Event) {
if(Event->type == SDL_QUIT) { //check for a quit
Running = false;
}
}
int CApp::OnExecute() {
if(OnInit() == false) {
return -1;
}
SDL_Event Event;
while(Running) {
while(SDL_PollEvent(&Event)) {
OnEvent(&Event);
}
OnRender();
}
OnCleanup();
return 0;
}
int main(int argc, char* argv[]) {
CApp theApp;
return theApp.OnExecute();
}