c++ singleton 懒汉模式(Meyers)VC6编译不过,该如何处理
c++ singleton 懒汉模式(Meyers)VC6编译不过
class Singleton
{
public:
static Singleton& Instance() {
static Singleton theSingleton;
return theSingleton;
}
private:
Singleton(); // ctor hidden
Singleton(Singleton const&); // copy ctor hidden
Singleton& operator=(Singleton const&); // assign op. hidden
~Singleton(); // dtor hidden
};
错误:
error C2248: 'Singleton::~Singleton' : cannot access private member declared in class 'Singleton'
我把析构函数改成public就可以编过了,如果说不能访问私有成员的话构造也是私有的为什么不报错,哪位大侠知道原因么?
------解决方案--------------------
换个编译器试试吧.
单这个代码,gcc编译是过的.
------解决方案--------------------
经测试vs2008可以正常通过编译。
vc6里面有一些是不符合c++标准的。
class Singleton
{
public:
static Singleton& Instance() {
static Singleton theSingleton;
return theSingleton;
}
private:
Singleton(); // ctor hidden
Singleton(Singleton const&); // copy ctor hidden
Singleton& operator=(Singleton const&); // assign op. hidden
~Singleton(); // dtor hidden
};
错误:
error C2248: 'Singleton::~Singleton' : cannot access private member declared in class 'Singleton'
我把析构函数改成public就可以编过了,如果说不能访问私有成员的话构造也是私有的为什么不报错,哪位大侠知道原因么?
------解决方案--------------------
换个编译器试试吧.
单这个代码,gcc编译是过的.
------解决方案--------------------
经测试vs2008可以正常通过编译。
vc6里面有一些是不符合c++标准的。