【发布时间】:2018-03-19 00:28:59
【问题描述】:
感谢您的关注。我是一些 VS2013 代码的新手,它是 C++ 加上一些微软特定扩展的混合体。该代码有一个类似
的类ref class Foo {
Bar^ bar_; // somewhere else, bar_ = gcnew Bar...
};
现在我需要添加一个非托管成员,从在线搜索看来我可以做到
ref class Foo {
Bar ^ bar_;
Unmanaged* ptr_; // somewhere else, ptr = new Unmanaged();
~Foo() {
this->!Foo();
}
!Foo() {
delete ptr_;
// do I need anything to deal with bar_?
}
};
问题是:
1) 这个终结器/析构函数是要走的路吗?
2) 既然我明确地编写了终结器/析构函数,我还需要为 bar_ 写任何额外的东西吗?
3) 有更清洁的方法吗?
【问题讨论】:
标签: c# c++ visual-c++ c++-cli