|
|
|
|
|
|
n*******r 发帖数: 22 | 1 在Visual Studio上编译总是有错,哪位大侠能不能帮我看看是什么原因?
error LNK2019: unresolved external symbol "private: __thiscall
Singleton2::Singleton2(void)" (??0?$Singleton2@H@@AAE@XZ)
referenced in function "public: static class Singleton2 * __cdecl
Singleton2::GetInstance(void)" (?
GetInstance@$Singleton2@H@@SAPAV1@XZ)
// Singleton.h
template class Singleton2
{
private:
Singleton2(void);
~Singleton2(void);
Singleton2(const Singleton2&);
Singleton2& operator=(const Singleton2&);
static Singleton2* instance;
public:
static Singleton2* GetInstance();
};
template Singleton2* Singleton2::instance = NULL;
template Singleton2* Singleton2::GetInstance()
{
if ( instance == NULL )
instance = new Singleton2;
return instance;
}
// Main program
#include "Singleton2.h"
void main()
{
Singleton2* s1 = Singleton2::GetInstance();
} | r*******m 发帖数: 109 | 2 because your default constructor is not defined. use this.
Singleton2(){};
【在 n*******r 的大作中提到】 : 在Visual Studio上编译总是有错,哪位大侠能不能帮我看看是什么原因? : error LNK2019: unresolved external symbol "private: __thiscall : Singleton2::Singleton2(void)" (??0?$Singleton2@H@@AAE@XZ) : referenced in function "public: static class Singleton2 * __cdecl : Singleton2::GetInstance(void)" (? : GetInstance@$Singleton2@H@@SAPAV1@XZ) : // Singleton.h : template class Singleton2 : { : private:
| n*******r 发帖数: 22 | 3 You're right! Thanks for the help.
【在 r*******m 的大作中提到】 : because your default constructor is not defined. use this. : Singleton2(){};
|
|
|
|
|
|