如何使用数组在C ++ / CX中定义结构

时间:2015-09-21 21:38:03

标签: c++-cx

以下工作正常:

public value struct Foo {
    Platform::String^ Name; 
    Platform::String^ Type;
};

但是,当我尝试添加Platform::Array<double>^时,我会收到一条错误消息。

public value struct Foo {
    Platform::String^ Name; 
    Platform::String^ Type;
    const Platform::Array<double>^ Value; 
};

错误讯息:

signature of public member contains invalid type 'const Platform::Array<double,1> ^

我也试过这个const Platform::Array<Platform::String^>^ Values。但我会有类似的错误信息:

signature of public member contains invalid type 'const Platform::Array<Platform::String ^,1> ^'

这是什么意思?我该如何解决这个问题?

修改:在这种情况下必须使用class,因为value struct只能包含基本数字类型,枚举类或Platform::String^字段。

public ref class Foo sealed {
    property Platform::String^ Name;
    property Platform::String^ Type;
    property Platform::Array<Platform::String^>^ Values;    
};

1 个答案:

答案 0 :(得分:1)

WinRT value struct(或value class)只能包含基本类型(数字,字符串等)[source]。它不能包含数组或引用类型(IReference<T>除外)。

感谢@Yuchen进行修改。