The C ++ Ref class is not a member of System :: IDisposable; problem with the implementation of IDisposable

I want to create a global vector of my own class of objects called "Man." However, the compiler says that

    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'

So, I looked at how to implement IDisposable (which, as I now know, is mainly used for unmanaged resources), but still cannot implement it with the following:

ref class Globals : System::IDisposable
{  
public: 
  static cliext::vector<Person^> person_data = gcnew cliext::vector<Person^>;
    void Dispose()
    {
         delete person_data;
    }
}; 

I get 2 errors:

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'
+3
source share
5 answers

From C ++ / CLI in action. The C ++ / CLI Dispose utility has these rules (rephrased):

  • destructor Dispose(bool), bool.
  • ' (~ ), (true), d'tor.
  • (! type) (false),

: IDisposable ( Dispose()). SuppressFinalize, , .

, , , - person_data . , , , error C2039: '{dtor}' : is not a member of 'System::IDisposable', .

, delete person_data, ? , , cliext , .

, ( ):

- , . , . , , : , , , .

-1

IDisposable. MSDN doco, :

ref class Globals
{
public:
    static cliext::vector<Person^> person_data = gcnew cliext::vector<Person^>;
    !Globals() // finalizer
    {
        delete person_data;
    {
protected:
    ~Globals() // destructor calls finalizer
    {
        this->!Globals();
    }
};
+3

. ++/CLI ~ ClassName() is Dispose() ! ClassName() # ~ ClassName(). :

ref class Globals : System::IDisposable
{  
public: 
    static cliext::vector<Person^> person_data = gcnew cliext::vector<Person^>;
    void ~Globals()
    {
        delete person_data;
    }
}; 
0

Dispose() . -. IDisposable , .

, person_data ( , gcnew) - (, , , , , , "." "- > " ).

, , , person_data "Globals", , , , ( )? , - Singleton , ?

0
source

Source: https://habr.com/ru/post/1731775/


All Articles