C#中的struct(值类型)可以实现IDisposable,如何在C ++ / CLI中实现相同的功能?
public value class MyStruct : public System::IDisposable
{
public:
// value types cannot contain user-defined special member functions
virtual ~MyStruct()
{
Console::WriteLine("DisposeCalled");
}
// a finalizer can only be a member of a reference type
!MyStruct()
{
Console::WriteLine("DisposeCalled");
}
// this method is reserved within a managed class
virtual void Dispose()
{
Console::WriteLine("DisposeCalled");
}
// 'Dispose' is not a member of 'System::IDisposable' (seriously?)
virtual void DisposeMe() = System::IDisposable::Dispose
{
Console::WriteLine("DisposeCalled");
}
};
我的尝试都没有成功(我已经逐一尝试过)。删除'虚拟'没有用。