我想制作一个名为“Person”的我自己的对象类的全局向量。然而,编译器说,C++ Ref类不是System :: IDisposable的成员;麻烦实施IDisposable
error C2039: '{dtor}' : is not a member of 'System::IDisposable'
1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::IDisposable'
于是我抬起头来如何实现IDisposable(我现在知道的是主要用于非托管资源),但似乎仍然无法与以下实现它:
ref class Globals : System::IDisposable
{
public:
static cliext::vector<Person^> person_data = gcnew cliext::vector<Person^>;
void Dispose()
{
delete person_data;
}
};
的2个错误,我得到的是:
error C2605: 'Dispose' : this method is reserved within a managed class
1> did you intend to define a destructor?
error C3766: 'Globals' must provide an implementation for the interface method 'void System::IDisposable::Dispose(void)'
1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::IDisposable::Dispose'
感谢您的回复,我认为这确实会有诀窍。不知道为什么那个析构错误不断出现。 – Dororo 2010-02-08 18:47:04
我似乎无法找到关于释放析构函数或终结器中的静态成员的任何信息。也许有人在那里知道答案并将分享。 – cmw 2010-02-08 19:01:00
静态成员由.cctor初始化,而不是在应用程序启动时初始化 – 2010-02-23 16:22:03