C ++ function call with reference parameter from cli

Unmanaged function (pure C ++, if that matters):

void fooC(float& result); 

I define the shell as (managed shell, C ++ \ cli):

 void foo(float% result) //managed interface, need to pass result back to caller { fooC(???);//how to call unmanaged function? } 

How to pass a reference parameter in a wrapper?

+4
source share
1 answer

You cannot convert a tracking link to an unmanaged link or pointer. The garbage collector can cause chaos when the passed float is a field in the object. You will need a temporary:

  void foo(float% result) { float temp; fooC(temp); result = temp; } 
+5
source

Source: https://habr.com/ru/post/1303882/


All Articles