【问题标题】:How do I define a struct in C++/CX with an array如何在 C++/CX 中使用数组定义结构
【发布时间】:2015-12-18 17:25:30
【问题描述】:

以下工作正常:

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&lt;Platform::String^&gt;^ 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;    
};

【问题讨论】:

  • 你见过this answer吗?
  • 显然值类型的结构不能使用泛型数组。

标签: c++-cx


【解决方案1】:

WinRT value struct(或value class)只能包含原始类型(数字、字符串等)[source]。它不能包含数组或引用类型(IReference&lt;T&gt; 除外)。

感谢@Yuchen 的修改。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-27
    • 2012-10-20
    • 2012-05-21
    • 2013-11-09
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 2013-04-01
    相关资源
    最近更新 更多