Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auto_ptr or shared_ptr equivalent in managed C++/CLI classes

In C++/CLI , you can use native types in a managed class by it is not allowed to hold a member of a native class in a managed class : you need to use pointers in that case.

Here is an example :

class NativeClass
{
....
};


public ref class ManagedClass
{
private:
  NativeClass mNativeClass; // Not allowed !

  NativeClass * mNativeClass; // OK

  auto_ptr<NativeClass> mNativeClass; //Not allowed !
  boost::shared_ptr<NativeClass> mNativeClass; //Not allowed !

};

Does anyone know of an equivalent of shared_ptr in the C++/CLI world?

Edit: Thanks for your suggestion, "1800-Information". Following your suggestion, I checked about STL.Net but it is only available with Visual Studio 2008, and it provides containers + algorithms, but no smart pointers.

like image 794
Pascal T. Avatar asked Oct 06 '08 22:10

Pascal T.


Video Answer


1 Answers

I found the answer on codeproject :

Nishant Sivakumar posted an article about this at http://www.codeproject.com/KB/mcpp/CAutoNativePtr.aspx

On this page, also look for the comment by Denis N. Shevchenko : he provides a stl-like implementation that works quite well.

like image 185
Pascal T. Avatar answered Oct 13 '22 03:10

Pascal T.