2014-02-27 132 views
0

我遇到了這個問題,即使它已被包含在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和靜態庫。

+1

g_editor :: LevelEditor構造函數的實現(不聲明)在哪裏? – PaulMcKenzie

回答

1

沒有定義LevelEditor::LevelEditor

您錯過了一個源文件,或者您忘記了{}

編輯:或者,如果您的構造函數無論如何都不做任何事情,只要刪除聲明即可。

+0

好神,我不敢相信。謝謝 –

0

要麼

1)該功能丟失:

LevelEditor(); // So now what does this do???? That's what is missing. 

2)它不缺,但你沒有添加源模塊或圖書館,這個功能位於您的鏈接器設置。

相關問題