在c ++中对类:: function的未定义引用 [英] Undefined reference to class::function in c++

查看:253
本文介绍了在c ++中对类:: function的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试调用OnLoop时,会收到无法识别的错误。

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

/// Ins_App.h

///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



///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

///OnLoop.cpp

#include "Ins_App.h"

void OnLoop(){

}

这里是错误:

obj \\ Debug \src\Ins_App.o:C:\Users\Al\Documents\Ins
\src\Ins_App.cpp | 19 |未定义引用`Ins_App :: OnLoop()' |

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

我做错了什么?

推荐答案

t定义您的成员:

void OnLoop(){

}

应为

void Ins_App::OnLoop(){

}

一个名为 OnLoop 的自由函数,而不是您的成员。

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

这篇关于在c ++中对类:: function的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆