开发者

System::IDisposable woes

开发者 https://www.devze.com 2022-12-22 16:27 出处:网络
public ref class ScriptEditor : public Form { public: typedef map<UInt32, ScriptEditor^>AlMap; static AlMapAllocationMap;
public ref class ScriptEditor : public Form
{
public:
    typedef map<UInt32, ScriptEditor^>                  AlMap;
    static AlMap                                        AllocationMap;

    Form^                                               EditorForm;     
    RichTextBox^                                        EditorBox;
    StatusBar开发者_StackOverflow^                                          EditorStatusBar;
    StatusBarPanel^                                     StatusBarLineNo;

    void                                                Destroy() { EditorForm->Close(); }
                                                        ScriptEditor(unsigned int PosX, unsigned int PosY);
};

The above code throws an Error C2039: '{dtor}' : is not a member of 'System::IDisposable'. I'm quite lost after having looked into articles that explain how the CLR manages memory. Any advice on getting rid of it would be appreciated. My first dabble in C+++/CLI isn't going too well.


You are not getting a very good error message. But the problem is that the STL map<> template class is only suitable for unmanaged types. It requires an element type to have a destructor, managed types don't have one. In the C++/CLI language, destructors are simulated with the IDisposable interface, that's the source of the confusing error message you see.

If you really want to use STL, you can with the STL/CLR implementation, available in VS2008. It is however pretty widely ignored as it basically combines the disadvantages of STL (expensive value semantics) with those of managed code (no default value semantics on reference types). This web page compares it to the native .NET collection classes, stark results to put it mildly.

The appropriate collection class to use here is System::Collections::Generic::Dictionary<>

0

精彩评论

暂无评论...
验证码 换一张
取 消