The following code works fine for Visual C++ 2008. However, when comes to Visual C++ 6, I get the following error. May I know why, and how I can fix the error, but still make the destructor remains in private.
class X
{
public:
static X& instance()
{
static X database;
return database;
}
private:
X() {} // Private constructor
~X() {} // Private destructor
X(const X&); // Prevent copy-construction
X& operator=(const X&); // Prevent assignment
};
int main()
{
X::instance();
}
C:\Projects\ttt6\main.cpp(178) : error C2248: 'X::~X' : cannot access private member declared in class 'X' C:\Projects\ttt6\main.cpp(175) : see declaration of 'X::~X'