我遇到了這個問題,即使它已被包含在main.h中後,我仍無法在main.cpp中調用對象構造函數。該錯誤信息是:對象構造函數的靜態庫「未定義的引用」
C:\Users\Espresso\Projects\AZRA\Debug/../src/main.cpp:7: undefined reference to `g_editor::LevelEditor::LevelEditor()'
凡main.cpp中包含
#include "main.h"
g_editor::LevelEditor g_levelEditor;
和main.h包含:
#include "g_editor/g_editor.h"
g_editor.h包含所有對象的頭文件該庫包括levelEditor。 g_editor.h:
#ifndef G_EDITOR_H_
#define G_EDITOR_H_
#pragma once
#include "g_editor/Objects/editor_module.h"
#include "g_editor/Objects/utility_window.h"
#include "g_editor/Objects/prompt_window.h"
#include "g_editor/LevelEditor/LevelEditor.h"
extern g_editor::LevelEditor g_levelEditor;
#endif
最後,LevelEditor.h包含關卡編輯器的構造函數和成員函數:
#ifndef G_LEVEL_EDITOR_H_
#define G_LEVEL_EDITOR_H_
#pragma once
#include "../Objects/editor_module.h"
#include "Modules/collisionGrid_module.h"
#include "Modules/HUD_module.h"
#include "Modules/IO_module.h"
#include "Modules/ledge_module.h"
#include "Modules/segment_module.h"
#include "g_level/g_level.h"
using namespace g_level;
namespace g_editor
{
class LevelEditor
{
private:
std::vector<editor_module*> modules;
void loadModules();
public:
static LevelEditor& get()
{
static LevelEditor sSingleton;
return sSingleton;
}
LevelEditor();
~LevelEditor() {};
我對文字的牆道歉,我已經在這個凝望了現在有幾天,我試着按優先順序對靜態庫進行重新排序(這消除了這個問題以外的所有問題。)我當前的設置中是否存在設計缺陷?我使用sSingletons,全局extern和靜態庫。
g_editor :: LevelEditor構造函數的實現(不聲明)在哪裏? – PaulMcKenzie