我正在使用visual studio 2013并收到此错误。
LNK2019:未解析的外部符号“public:static class CAIUInterface * __cdecl:GetInstance(void)“
(?GetInstance @ CAIUInterface @@ SAPAV1 @ XZ)在函数中引用 “public:int call CAppAIUInterface :: CloseApp(void)” (?CloseApp @ CAppAIUInterface @@ QAEHXZ)D:\ 15008_CPDS \ CPDS \ AppAIUInterface.obj CPDS
CAIUInterface
是一个单身人士类。
// below is CAIUInterface.h
#include "std429.h"
#include <functional>
using namespace std;
class CAppAIUInterface;
class CAIUInterface
{
private:
static bool m_bInstanceFlag;
static CAIUInterface *m_objAIU;
protected:
CAIUInterface();
public:
//Destructor
~CAIUInterface();
static CAIUInterface* GetInstance();
int Close();
};
// CAIUInterface.cpp file
#include <windows.h>
#include "AIUInterface.h"
using namespace std::placeholders;
bool CAIUInterface::m_bInstanceFlag = false;
CAIUInterface* CAIUInterface::m_objAIU = NULL;
CAIUInterface* CAIUInterface::GetInstance()
{
if (!m_bInstanceFlag)
{
m_objAIU = new CAIUInterface();
m_bInstanceFlag = true;
}
return m_objAIU;
}
// APPAIUInterface.h
#include "Transmitter.h"
class CAppAIUInterface
{
private:
CTransmitter m_objTrans;
public:
CAppAIUInterface();
~CAppAIUInterface();
int CloseApp();
};
// APPAIUInterface.cpp
int CAppAIUInterface::CloseApp()
{
unsigned int siResult = 0;
siResult = CAIUInterface::GetInstance()->Close();
if (siResult != CPDS_SUCCESS)
return ERR_APP_AIU_CLOSE;
return CPDS_SUCCESS;
}