views:

42

answers:

1
public ref class ScriptEditor : public Form
{
public:
    typedef map<UInt32, ScriptEditor^>                  AlMap;
    static AlMap                                        AllocationMap;

    Form^                                               EditorForm;     
    RichTextBox^                                        EditorBox;
    StatusBar^                                          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.

+1  A: 

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<>

Hans Passant
I am using the CLR implementation of the map container - Must have mentioned that earlier. In any case, I'll try using the Dictionary class.
shadeMe
Well, it is described well in the linked documentation, STL/CLR requires ScriptEditor to implement ~ScriptEditor(). But yes, use Dictionary<>.
Hans Passant
Once again, I'm at fault for not having posted the completed code, intact. I did implement the destructor at one point, but the error message still lingered.
shadeMe