为什么Visual C++ 6抱怨私有析构函数

Che*_*eng 5 c++

下面的代码适用于Visual C++ 2008.但是,当涉及到Visual C++ 6时,我收到以下错误.我可以知道为什么,以及如何解决错误,但仍然使析构函数保持私有状态.

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();
}
Run Code Online (Sandbox Code Playgroud)

C:\ Projects\ttt6\main.cpp(178):错误C2248:'X :: ~X':无法访问类'X'中声明的私有成员C:\ Projects\ttt6\main.cpp(175):请参阅'X ::〜X'的声明

Geo*_*che 7

修订后的示例显示了VC6的确认编译器错误 - 常见的解决方法是简单地将析构函数公开.