C++/CLI 不能调C# class 的 Dispose()方法

xiehuanxie xiehuanxie 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我有一个C# class 实现了IDisposable接口


public class Matrix<T> : IDisposable, ICloneable, IEnumerable<T>
{

...

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}


在C#里面调用都是没问题的, 但是在c++里调用里出现编译错误:
Error 1 error C2039: 'Dispose' : is not a member of ‘Mathematics::Matrix<T>'

output:
error C2039: 'Dispose' : is not a member of 'InScan::Infrastructure::Common::Mathematics::Matrix<T>'
1> with
1> [
1> T=byte
1> ]
1> You should invoke the destructor, '~Matrix<unsigned char>' instead

所以我现在只能这样:

delete matrix;
GC::Collect();


为什么Dispose()方法在C++里面会调不到?
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
xiehuanxie
C# 111,130 成员 642,541 内容