C# 将简单C结构编组到C++;当C++;版本需要无参数构造函数 强>此问题只发生在Windows存储项目中的C++ DLL并在设备上运行时。当与Android或iOS项目一起使用时,它可以正常工作。 我在一些本地C++代码中有这样的结构: struct InteropVector2 { float32 x; float32 y; InteropVector2(float32 x, float32 y) : x(x), y(y) {} InteropVector2() {} }; [StructLayout (LayoutKind.Sequential, Pack = 4)] public struct InteropVector2 { public float x; public float y; public InteropVector2(float x, float y) { this.x = x; this.y = y; } }

C# 将简单C结构编组到C++;当C++;版本需要无参数构造函数 强>此问题只发生在Windows存储项目中的C++ DLL并在设备上运行时。当与Android或iOS项目一起使用时,它可以正常工作。 我在一些本地C++代码中有这样的结构: struct InteropVector2 { float32 x; float32 y; InteropVector2(float32 x, float32 y) : x(x), y(y) {} InteropVector2() {} }; [StructLayout (LayoutKind.Sequential, Pack = 4)] public struct InteropVector2 { public float x; public float y; public InteropVector2(float x, float y) { this.x = x; this.y = y; } },c#,c++,struct,marshalling,default-constructor,C#,C++,Struct,Marshalling,Default Constructor,很简单,没什么特别的。所以我在C语言中创建了另一个结构,当我需要把这个结构从C++中传递到C++时,看起来像: struct InteropVector2 { float32 x; float32 y; InteropVector2(float32 x, float32 y) : x(x), y(y) {} InteropVector2() {} }; [StructLayout (LayoutKind.Sequential, Pack = 4)] publ

很简单,没什么特别的。所以我在C语言中创建了另一个结构,当我需要把这个结构从C++中传递到C++时,看起来像:
struct InteropVector2 {
    float32 x;
    float32 y;

    InteropVector2(float32 x, float32 y) : x(x), y(y) {}

    InteropVector2() {}
};
[StructLayout (LayoutKind.Sequential, Pack = 4)]
public struct InteropVector2
{
    public float x;
    public float y;

    public InteropVector2(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
}
也很简单。但是,当我从C到C++的时候,x和y的值是0,不管我通过什么。但是,如果我移除C++结构中的无参数构造函数,它就好像是一个符咒。< /强>我需要在C++代码中拥有无参数的构造函数。你知道我怎样才能做到这一点吗

以下是使用这些结构的示例:

C++

C#


我想这和背包有关。作为测试,尝试移动32 x,y;在C++结构的顶部,并添加PrimaMax包,如C语言所示。我将浮动移到C++结构的顶部,并添加了“γ”语法包(4)。尽管如此,但是在C++中删除默认构造函数是很奇怪的。编辑:把它加粗,这样人们就可以把注意力集中在这个问题上。是的,它确实非常古怪。我唯一要做的就是注释/取消注释无参数构造函数。我已经验证过这几次了,因为它看起来不太可能。哦,我应该补充说,这只发生在使用Windows DealStore项目中的C++ DLL并在设备上运行它时。很抱歉,这是非常重要的信息。我将编辑这个问题。
var = B2D.TestMyVector2(new InteropVector2(1.44f, 2.55f)));