好了,所以我剛剛完成我最後的編譯器錯誤(所以我認爲),這些錯誤想出了:錯誤LNK2001和錯誤LNK2019(C++) - 請求一些瞭解這些錯誤
1>GameEngine.obj : error LNK2001: unresolved external symbol "public: static double WeaponsDB::PI" ([email protected]@@2NA)
1>Component.obj : error LNK2001: unresolved external symbol "public: static double WeaponsDB::PI" ([email protected]@@2NA)
1>Coordinate.obj : error LNK2019: unresolved external symbol "public: static double WeaponsDB::PI" ([email protected]@@2NA) referenced in function "public: double __thiscall Coordinate::distanceFrom(class Coordinate *)" ([email protected]@@[email protected]@Z)
1>Driver.obj : error LNK2001: unresolved external symbol "public: static double WeaponsDB::PI" ([email protected]@@2NA)
1>Environment.obj : error LNK2001: unresolved external symbol "public: static double WeaponsDB::PI" ([email protected]@@2NA)
1>Environment.obj : error LNK2001: unresolved external symbol "public: static bool Environment::spyFlag" ([email protected]@@2_NA)
1>Environment.obj : error LNK2001: unresolved external symbol "private: static class Environment * Environment::instance_" ([email protected]@@[email protected])
1>Environment.obj : error LNK2019: unresolved external symbol "public: static void __cdecl Environment::spyAlertOver(void)" ([email protected]@@SAXXZ) referenced in function "public: void __thiscall Environment::notificationOfSpySuccess(void)" ([email protected]@@QAEXXZ)
1>GameDriver.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MainMenu::gameOver(int)" ([email protected]@@[email protected]) referenced in function "public: static void __cdecl GameDriver::run(void)" ([email protected]@@SAXXZ)
1>GameDriver.obj : error LNK2019: unresolved external symbol "public: static void __cdecl GameDriver::gatherInput(void)" ([email protected]@@SAXXZ) referenced in function "public: static void __cdecl GameDriver::run(void)" ([email protected]@@SAXXZ)
1>GameDriver.obj : error LNK2019: unresolved external symbol "public: static void __cdecl GameDriver::ticker(void)" ([email protected]@@SAXXZ) referenced in function "public: static void __cdecl GameDriver::run(void)" ([email protected]@@SAXXZ)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static int GameDriver::ticks" ([email protected]@@2HA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::evaluatingInputFlag" ([email protected]@@2_NA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::keyQuitFlag" ([email protected]@@2_NA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::keyToggleWeaponRightFlag" ([email protected]@@2_NA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::keyToggleWeaponLeftFlag" ([email protected]@@2_NA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::keyFireFlag" ([email protected]@@2_NA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::keyLeftFlag" ([email protected]@@2_NA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::keyRightFlag" ([email protected]@@2_NA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::keyUpFlag" ([email protected]@@2_NA)
1>GameDriver.obj : error LNK2001: unresolved external symbol "public: static bool GameDriver::keyDownFlag" ([email protected]@@2_NA)
1>GUI_Env.obj : error LNK2001: unresolved external symbol "private: static struct BITMAP * GUI_Env::buffer" ([email protected][email protected]@[email protected]@A)
1>GUI_Info.obj : error LNK2001: unresolved external symbol "private: static struct BITMAP * GUI_Info::buffer" ([email protected][email protected]@[email protected]@A)
1>MenuDriver.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MainMenu::displayMenu(void)" ([email protected]@@SAXXZ) referenced in function "public: static void __cdecl MenuDriver::start(void)" ([email protected]@@SAXXZ)
1>SpaceObjectFactory.obj : error LNK2001: unresolved external symbol "private: static class SpaceObjectFactory * SpaceObjectFactory::_instance" ([email protected]@@[email protected])
1>Spy.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall UnFormationable::sameTypeOfSpaceObjectAs(class SpaceObject *)" ([email protected]@@[email protected]@@Z) referenced in function "public: virtual bool __thiscall Spy::sameTypeOfSpaceObjectAs(class SpaceObject *)" ([email protected]@@[email protected]@@Z)
1>WeaponsDB.obj : error LNK2001: unresolved external symbol "private: static class WeaponsDB * WeaponsDB::_instance" ([email protected]@@[email protected])
1>C:\Users\Owner\Desktop\Bosconian\code\Bosconian\Debug\Bosconian.exe : fatal error LNK1120: 23 unresolved externals
好吧,這裏的簡要概述。
PI是WeaponsDB靜態常量,並且通過使用WeaponsDB :: PI和適當的#include(這有什麼錯呢?)
大多數其他錯誤,從靜態的變量和定時器的靜態方法阻止其他類引用來自allegro遊戲庫。
什麼原因導致這些錯誤,我該如何擺脫它們?
在此先感謝
----------------編輯-------------------
按要求,WeaponsDB :: PI被聲明和定義。 它在WeaponsDB.h聲明:
public:
static double PI;
卻是在另一個類Driver.cpp定義:
WeaponsDB::PI = 4*atan(1.0);
如果這是我的代碼的一個問題我很想知道爲什麼這會導致錯誤。
您需要發佈聲明PI的.h文件的部分以及定義它的.cpp文件。 – 2008-12-19 05:20:20