Undefined reference to class::function in c++

最后都变了- 提交于 2019-12-12 03:47:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10340862/undefined-reference-to-classfunction-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!