64,681
社区成员
发帖
与我相关
我的任务
分享
template<typename T> class CPVRTSingleton
{
private:
CPVRTSingleton(const CPVRTSingleton&);
CPVRTSingleton & operator=(const CPVRTSingleton&);
public:
static T& inst()
{
static T object;
return object;
}
static T* ptr()
{
return &inst();
}
protected:
CPVRTSingleton() {};
virtual ~CPVRTSingleton() {};
};
class TextureManager : public CPVRTSingleton<TextureManager>
{
public:
TextureManager(){};
~TextureManager();//cpp里有实现
TextureManager(int i32TotalTextures);//cpp里有实现
....
}
// LNK2019e.cpp
// compile with: /EHsc
// LNK2019 expected
#include <iostream>
using namespace std;
template<class T> class
Test {
friend ostream& operator<<(ostream&, Test&);
// Uncomment the following line to resolve.
// template<typename T> friend ostream& operator << (ostream&, Test<T>&);
};
template<typename T>
ostream& operator<<(ostream& os, Test<T>& tt) {
return os;
}
int main() {
Test<int> t;
cout << "Test: " << t << endl; // unresolved external
}
template<typename T>
class CPVRTSingleton
{
private:
CPVRTSingleton(const CPVRTSingleton&)
{
}
CPVRTSingleton & operator=(const CPVRTSingleton&)
{
return *this;
}
public:
static T& inst()
{
static T object;
return object;
}
static T* ptr()
{
return &inst();
}
protected:
CPVRTSingleton()
{
}
virtual ~CPVRTSingleton()
{
}
};
class TextureManager : public CPVRTSingleton<TextureManager>
{
public:
TextureManager()
{
}
~TextureManager()
{
}
TextureManager(int i32TotalTextures)
{
}
};
int main()
{
TextureManager tm;
return 0;
}