因此,我正在使用olcConsoleGameEngine(由于其太大而无法复制粘贴https://github.com/OneLoneCoder/videos/blob/master/olcConsoleGameEngine.h),并且我正在使用从其继承的类作为游戏的基础,这是头文件:
Game.h
#ifndef GAME_H
#define GAME_H
#include "olcConsoleGameEngine.h"
class Game : public olcConsoleGameEngine
{
public:
Game();
protected:
/*
virtual bool OnUserCreate()
{
return true;
}
virtual bool OnUserUpdate(float fElapsedTime)
{
Fill(0, 0, ScreenWidth(), ScreenHeight(), PIXEL_SOLID, FG_BLUE);
return true;
}
*/
virtual bool OnUserCreate();
virtual bool OnUserUpdate(float fElapsedTime);
};
#endif
注意注释,声明和定义这种方式是到目前为止我唯一可以编译的方式(确保同时删除cpp中的声明)
Game.cpp
#include "Game.h"
Game::Game()
{
}
bool Game::OnUserCreate()
{
return true;
}
bool Game::OnUserUpdate(float fElapsedTime)
{
return true;
}
总的来说,我只有用于设置窗口的标准代码,因为在.h中声明Update和Create函数的工作没有错误并且给出了正确的输出,所以我知道这是有效的。似乎一旦我在Game.cpp中包含Game.h,我就会得到链接器错误,即:
1>main.obj : error LNK2005: "void __cdecl GetFontCoords(int,int *,int *)" (?GetFontCoords@@YAXHPAH0@Z) already defined in Game.obj
1>main.obj : error LNK2005: "void __cdecl font_decode_custom_base64(void)" (?font_decode_custom_base64@@YAXXZ) already defined in Game.obj
1>main.obj : error LNK2005: "protected: static struct std::atomic<bool> olcConsoleGameEngine::m_bAtomActive" (?m_bAtomActive@olcConsoleGameEngine@@1U?$atomic@_N@std@@A) already defined in Game.obj
1>main.obj : error LNK2005: "int (__stdcall* wglSwapInterval)(int)" (?wglSwapInterval@@3P6GHH@ZA) already defined in Game.obj
1>main.obj : error LNK2005: "unsigned char * pxplus_ibm_cga" (?pxplus_ibm_cga@@3PAEA) already defined in Game.obj
1>main.obj : error LNK2005: "char * pxplus_ibm_cga_enc" (?pxplus_ibm_cga_enc@@3PADA) already defined in Game.obj
1>main.obj : error LNK2005: "protected: static class std::condition_variable olcConsoleGameEngine::m_cvGameFinished" (?m_cvGameFinished@olcConsoleGameEngine@@1Vcondition_variable@std@@A) already defined in Game.obj
1>main.obj : error LNK2005: "protected: static class std::mutex olcConsoleGameEngine::m_muxGame" (?m_muxGame@olcConsoleGameEngine@@1Vmutex@std@@A) already defined in Game.obj
1>C:\Dev\C++Projects\WarAutomata\Debug\WarAutomata.exe : fatal error LNK1169: one or more multiply defined symbols found
Main.cpp
#include "Game.h"
int main() {
Game game;
game.ConstructConsole(640, 480, 1, 1);
game.Start();
return 0;
}
所以在程序的当前状态下,我将在头文件中声明每个函数,这显然不是理想的选择。对这个问题的任何帮助将不胜感激。