error: no 'bool CApp::OnDraw(`...'member function declared in class 'CApp'

This is a discussion on error: no 'bool CApp::OnDraw(`...'member function declared in class 'CApp' within the C++ Programming forums, part of the General Programming Boards category; This has been bugging the hell out of me and has driven me to close my ide in frustration far ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    3

    error: no 'bool CApp::OnDraw(`...'member function declared in class 'CApp'

    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();
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    So why did you declare them to be static?

    If you want to stop the outside world from using them, move them to the private: section of the class.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    Quote Originally Posted by Salem View Post
    So why did you declare them to be static?

    If you want to stop the outside world from using them, move them to the private: section of the class.
    This code was originally from a tutorial that split up the functions into 5 different files, this is my attempt to merge the code and header files. The code is verbatim, so I can't really tell you what the author was doing when they wrote it. I tried removing the static just to see if it magically would work, but it did not

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    > CApp::OnDraw(Surf_Display, Surf_Test, 0, 0);
    Did you also remove CApp:: from here?

    You know, just to make it look like everything else.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    3
    Quote Originally Posted by Salem View Post
    > CApp::OnDraw(Surf_Display, Surf_Test, 0, 0);
    Did you also remove CApp:: from here?

    You know, just to make it look like everything else.
    You have no idea the size of the facepalm that was just had.

    Thanks for the help.

    edit: more funtimes! When fixing the functions, I no longer have problems with the OnDraws, however I get an error that OnLoad was not declared in the scope on this line
    Code:
    if((Surf_Test = OnLoad("myimage.bmp")) == NULL) {
    This isn't my day :/
    Last edited by zanielyene; 12-04-2010 at 03:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem defining structure
    By MTK in forum C Programming
    Replies: 12
    Last Post: 09-08-2009, 03:26 PM
  2. Passing class member function to pthread_create
    By lehe in forum C++ Programming
    Replies: 6
    Last Post: 03-27-2009, 07:47 PM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Replies: 6
    Last Post: 04-27-2006, 10:55 AM
  5. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21