CLI包装器-奇怪的问题 [英] CLI wrapper - weird problem
本文介绍了CLI包装器-奇怪的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我有一个用c ++编写的类
let''s say I have a class written in c++
class Foo
{
...
const Foo operator / (Foo& other_Foo)
{
//internal calculus for division
//returns new foo
}
...
}
现在我写了一个cli包装器
and now I wrote a cli wrapper
public ref class ManagedFoo
{
...
ManagedFoo divide(ManagedFoo& other_ManagedFoo)
{
//how do I call here the divide from the unmanaged???
}
...
}
推荐答案
好吧,我找到了一个解决方案...相当简单...某种复制构造函数.
Well I found a solution...rather straightforward...some sort of copy constructor.
ManagedFoo(ManagedFoo% other_ManagedFoo):Foo_point(other_ManagedFoo.get_native()){}
那就是因为如果我有2个托管foo实例,我想通过调用以下方法获得第三个实例:
thats because If I have 2 managed foo instances I want to get the third by calling:
ManagedFoo one( /*...*/ );
ManagedFoo two( /*...*/ );
ManagedFoo three = one.divide(two);
这是除法实现的代码:
this is the code for the divide implementation:
ManagedFoo ManagedFoo::divide(ManagedFoo %other_ManagedFoo)
{
Foo res = Foo_point->operator/ (*(other_ManagedFoo.get_native()));
ManagedFoo result(new Foo(res));
return result;
}
您可以说.get_native()返回本机实例的指针.
You can tell that .get_native() returns the pointer of the native instance.
这篇关于CLI包装器-奇怪的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文