auto_ptr或shared_ptr等价于托管C ++ / CLI类 [英] auto_ptr or shared_ptr equivalent in managed C++/CLI classes
问题描述
在C ++ / CLI中,您可以在托管类中使用本机类型,因为它不允许在托管类中保存本机类的成员:在这种情况下,您需要使用指针。
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.
下面是一个例子:
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 !
};
有人知道在C ++ / CLI世界中有相当于shared_ptr吗?
Does anyone know of an equivalent of shared_ptr in the C++/CLI world?
编辑:
感谢您的建议,1800-Information。根据你的建议,我检查了STL.Net,但它只适用于Visual Studio 2008,它提供了容器+算法,但没有智能指针。
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.
推荐答案
我在代码项目上找到了答案:
Nishant Sivakumar在 http://www.codeproject.com上发布了一篇文章/KB/mcpp/CAutoNativePtr.aspx
Nishant Sivakumar posted an article about this at http://www.codeproject.com/KB/mcpp/CAutoNativePtr.aspx
在此页面上,还查找Denis N. Shevchenko的评论:他提供了一个类似stl的实现工作得很好。
On this page, also look for the comment by Denis N. Shevchenko : he provides a stl-like implementation that works quite well.
这篇关于auto_ptr或shared_ptr等价于托管C ++ / CLI类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!