【问题标题】:How to implement GetMany method from IVector interface如何从 IVector 接口实现 GetMany 方法
【发布时间】:2015-02-04 07:29:51
【问题描述】:

我尝试创建 ICollectionView 的自定义实现,但我的应用尚未通过认证。原因是 WACK 工具指出 GetMany 方法的签名与 windows.winmd 中 GetMany 的签名不匹配

以下是 windows.winmd 对 GetMany 的评价:

unsigned int GetMany(unsigned int startIndex, [Windows::Foundation::Metadata::LengthIsAttribute] Platform::Array<T>^ items)

不过,根据编译器的提示,我是这样定义 GetMany 方法的:

virtual unsigned int GetMany(unsigned int index, Platform::WriteOnlyArray<Platform::Object^>^ items);

它可以编译并且工作正常,但是 WACK 抱怨它。我还发现 Array 作为输出参数可以这样实现:

virtual unsigned int GetMany(unsigned int index, Platform::Array<Platform::Object^>^* items);

但是,在这种情况下,编译器说我的类是抽象的,它错过了 GetMany 方法的实现。我什至尝试实现这两种方法,但这会破坏编译器。

我可以采用解决方法并以不同的方式实现功能(没有 ICollectionView),但是从设计的角度来看,这个解决方案最适合我。

【问题讨论】:

  • 这一定是一个 WACK 错误,我很确定 IVector::GetMany() 使用 FillArray pattern 所以 WriteOnlyArray 是正确的。我谷歌的其他代码也使用它。使用确切的 WACK 错误消息更新您的问题,考虑在 connect.microsoft.com 提交错误报告
  • 我有波兰语的信息,所以没什么用。自从 MS 开始翻译其开发工具以来,我们这些非英语母语人士在谷歌搜索问题解决方案方面遇到了问题。我会试试 connect.microsoft.com

标签: windows-store-apps c++-cx


【解决方案1】:

查看安装中的collection.h(它定义了Platform::VectorView 的实现)可能很有启发性。它将 GetMany 函数定义为:

virtual unsigned int GetMany(unsigned int startIndex, WriteOnlyArray<T>^ dest)

所以你想使用WriteOnlyArray 是正确的。您的集合是否以 Object^ 类型为模板?

关于不同 WinRT 数组模式及其用途的隐蔽但内容丰富的 MSDN 主题:https://msdn.microsoft.com/en-us/library/windows/apps/hh700131.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多