我遇到了这个问题,即使它已被包含在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