相关疑难解决方法(0)

C++/CLI-> C#错误C2526:C连接函数无法返回C++类

我有一个使用VS2010 C#构建的简单.NET dll,它暴露了一个类的2个静态成员

public class Polygon
{
    public static void Test(int test) {}
    public static void Test(List<int> test) {}
}
Run Code Online (Sandbox Code Playgroud)

然后我从VS2010 C++创建了一个Console应用程序,并在_tmain上面添加了这个函数

extern "C" void TestMe()
{
    Polygon::Test(3);
}
Run Code Online (Sandbox Code Playgroud)

添加引用和编译会给我这个错误

1>WierdError.cpp(9): error C2526: 'System::Collections::Generic::List<T>::GetEnumerator' : C linkage function cannot return C++ class 'System::Collections::Generic::List<T>::Enumerator'
1>          with
1>          [
1>              T=int
1>          ]
1>          WierdError.cpp(9) : see declaration of 'System::Collections::Generic::List<T>::Enumerator'
1>          with
1>          [
1>              T=int
1>          ]
1>          WierdError.cpp(9) : see reference to class generic instantiation 'System::Collections::Generic::List<T>' being compiled
1>          with …
Run Code Online (Sandbox Code Playgroud)

c# c++-cli visual-studio-2010 extern linkage

9
推荐指数
1
解决办法
3836
查看次数

标签 统计

c# ×1

c++-cli ×1

extern ×1

linkage ×1

visual-studio-2010 ×1