I’ve a C# class library with overloaded methods, and one method has a ref parameter and the other has a value parameter. I can call these methods in C#, but I can’t get it right in C++/CLI. It’s seems compiler can’t distinguish these two methods.
Here is my C# code
namespace test {
public class test {
public static void foo(int i)
{
i++;
}
public static void foo(ref int i)
{
i++;
}
}
}
and my C++/CLI code
int main(array<System::String ^> ^args)
{
int i=0;
test::test::foo(i); //error C2668: ambiguous call to overloaded function
test::test::foo(%i); //error C3071: operator '%' can only be applied to an instance of a ref class or a value-type
int %r=i;
test::test::foo(r); //error C2668: ambiguous call to overloaded function
Console::WriteLine(i);
return 0;
}
I know in C++ I can’t declare overload functions where the only difference in the function signature is that one takes an object and another takes reference to an object, but in C# I can.
Is this a feature supported in C# but not in C++/CLI? Is there any workaround?
As a workaround you could build a C# helper class that you use in C++/CLI