auto gcroot : gcroot « Language Basics « Visual C++ .NET






auto gcroot

 
#include "stdafx.h"
#include <msclr/gcroot.h>
#include <msclr/auto_gcroot.h>
using namespace System;
using namespace msclr;

ref class MyClass
{
   public:
     void f()
     {
        Console::WriteLine("managed member function");
     }

     ~MyClass()
     {
        Console::WriteLine("destructor");
     }
    
};

class N
{  
   gcroot<MyClass^> r_gcroot;
   auto_gcroot<MyClass^> r_auto_gcroot;

   public:
      N()
      {
          r_gcroot = gcnew MyClass();
          r_gcroot->f();
          r_auto_gcroot = gcnew MyClass();
          r_auto_gcroot->f();
      }
      
};

int main()
{
   N n;
}

   
  








Related examples in the same category

1.gcroot and auto gcroot