0
構建我的程序時出現鏈接錯誤。問題似乎是我的NetworkManager單身人士通過friend語句被拉入Networkable。我讀過在.hpp文件中有實例聲明時會發生這種情況,但如果instance()函數沒有以某種方式內聯,這不應該是我的情況。單身人士引起鏈接錯誤的朋友聲明
我在這裏發現了類似的問題,但沒有人回答我的問題。有什麼建議麼?
// Networkable.hpp
#pragma once
class Networkable
{
friend class NetworkManager;
public:
....
//NetworkManager.hpp
#pragma once
class Networkable;
class NetworkManager
{
public:
static NetworkManager &instance();
~NetworkManager();
void registerNetworkable(Networkable *networkable);
void unregisterNetworkable(Networkable *networkable);
void update();
...
// errors:
1>NetworkManager.obj : error LNK2005: "public: __thiscall NetworkManager::~NetworkManager(void)" ([email protected]@[email protected]) already defined in Networkable.obj
1>NetworkManager.obj : error LNK2005: "public: static class NetworkManager & __cdecl NetworkManager::instance(void)" ([email protected]@@[email protected]) already defined in Networkable.obj
1>NetworkManager.obj : error LNK2005: "public: void __thiscall NetworkManager::registerNetworkable(class Networkable *)" ([email protected]@@[email protected]@@Z) already defined in Networkable.obj
1>NetworkManager.obj : error LNK2005: "public: void __thiscall NetworkManager::unregisterNetworkable(class Networkable *)" ([email protected]@@[email protected]@@Z) already defined in Networkable.obj
1>NetworkManager.obj : error LNK2005: "public: void __thiscall NetworkManager::update(void)" ([email protected]@@QAEXXZ) already defined in Networkable.obj