帮我看看单例模式有啥问题?
#include <memory>
#include <iostream>
using namespace std;
template<class T>
class Singleton
{
public:
static T *Instance()
{
if(instance_.get() == NULL)
instance_.reset(new T);
return instance_.get();
}
virtual ~Singleton(){}
protected:
Singleton(){}
private:
static std::auto_ptr<T> instance_;
};
template<class T>
std::auto_ptr<T> Singleton<T>::instance_;
class T : protected Singleton<T>
{
public:
void print(){cout << "this is a stest" << endl; }
};
int _tmain(int argc, _TCHAR* argv[])
{
T t; // 这样竟然能运行通过
t.print();
// T::Instance()->print();
return 0;
}