Atrus
Atrus

Reputation: 25

Undefined reference to class::function in c++

When I try to call OnLoop I get error that it doesn't recognise it.

///Ins_App.h

#ifndef INS_APP_H
#define INS_APP_H

#include <SDL/SDL.h>

class Ins_App
{
    private:
        /*   Variables   */
        bool Running;
        SDL_Surface* Surf_Display;

    public:
        /*  inMain  */
        Ins_App();
        int OnExecute();

    public:
        /*  Other   */

        bool OnInit();
        void OnEvent(SDL_Event* Event);
        void OnLoop();
        void OnRender();
        void OnCleanup();

    protected:
};

#endif // INS_APP_H

///Ins_App.cpp

#include "Ins_App.h"

Ins_App::Ins_App()
{
    Running = true;
    Surf_Display = NULL;
}

int Ins_App::OnExecute(){

    if(OnInit() == false){
        return -1;
    }
    SDL_Event Event;
    while(Running){
        while(SDL_PollEvent(&Event)){
            OnEvent(&Event);
        }
        OnLoop();
        OnRender();
    }
    return 0;
}

int main(int argc, char* argv[]){

    Ins_App iApp;
    return iApp.OnExecute();

}

///OnLoop.cpp

#include "Ins_App.h"

void OnLoop(){

}

And here is the error:

obj\Debug\src\Ins_App.o:C:\Users\Al\Documents\Ins \src\Ins_App.cpp|19|undefined reference to `Ins_App::OnLoop()'|

What am I doing wrong?

Upvotes: 0

Views: 5004

Answers (1)

Luchian Grigore
Luchian Grigore

Reputation: 258678

You didn't define your member:

void OnLoop(){

}

should be

void Ins_App::OnLoop(){

}

You're basically just defining a free function named OnLoop, not your member.

Upvotes: 9

Related Questions