我已经在Stackoverflow中查找了这类问题的一些答案,其中没有一个能帮助我。 This问题描述了如何解决此错误,并且我应该提供定义而不仅仅是声明。我已经做到了,但我仍然收到以下错误:
错误13错误LNK2019:未解析的外部符号"私有:__ thiscall NetworkManager :: NetworkManager(void)" (?? 0NetworkManager @@ AAE @XZ)在函数" public中引用:static class NetworkManager * __cdecl NetworkManager :: Instance(void)" (?Instance @ NetworkManager @@ SAPAV1 @XZ)C:\ Users \ HIDDEN \ Documents \ AGK Projects \ C ++ Libraries \ apps \ template_windows_vs2013 \ NetworkManager.obj Template
以下是代码:
NetworkManager.h
#ifndef _H_NETWORKMANAGER_
#define _H_NETWORKMANAGER_
#include<iostream>
#include<vector>
class NetworkManager
{
private:
NetworkManager();
static NetworkManager * netManager;
public:
int networkID;
static NetworkManager * Instance();
int HostNetwork(std::string netName, std::string hostName, int port);
int JoinNetwork(std::string netName, std::string clientName);
bool IsNetworkActive(int netID);
};
#endif
NetworkManager.cpp
#include<iostream>
#include "NetworkManager.h"
#include "template.h"
NetworkManager * NetworkManager::netManager = NULL;
NetworkManager * NetworkManager::Instance()
{
if (!netManager)
netManager = new NetworkManager;
return netManager;
}
int NetworkManager::HostNetwork(std::string netName, std::string hostName, int port)
{
int networdID__;
const char * netName__ = netName.c_str();
const char * hostName__ = hostName.c_str();
networdID__ = agk::HostNetwork(netName__, hostName__, port);
return networdID__;
}
int NetworkManager::JoinNetwork(std::string netName, std::string clientName)
{
int networdID__;
const char * netName__ = netName.c_str();
const char * clientName__ = clientName.c_str();
networdID__ = agk::JoinNetwork(netName__, clientName__);
return networdID__;
}
bool NetworkManager::IsNetworkActive(int netID)
{
switch (agk::IsNetworkActive(netID))
{
case 0: return false; break;
case 1: return true; break;
}
}
答案 0 :(得分:3)
您在头文件中声明了NetworkManager::NetworkManager()
,但源文件中没有实现它。