加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-runtime – 如何在C/C++X中迭代IIterable?

发布时间:2020-12-14 02:14:48 所属栏目:Windows 来源:网络整理
导读:(这也可以表述为“我如何迭代从C/C++X中的C# Windows运行时组件返回的集合?”) 我试图在IIterable T上使用std :: for_each.但得到以下编译时错误 error C2664: ‘std::begin’ : cannot convert parameter 1 from ‘my_collection_type ^’ to ‘Platform::
(这也可以表述为“我如何迭代从C/C++X中的C# Windows运行时组件返回的集合?”)

我试图在IIterable< T>上使用std :: for_each.但得到以下编译时错误

error C2664: ‘std::begin’ : cannot convert parameter 1 from
‘my_collection_type ^’ to ‘Platform::String ^’ No
user-defined-conversion operator available,or Types
pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast

我如何迭代收藏?

解决方法

为此,您需要添加

#include "collection.h"

(和可选的)

using namespace Windows::Foundation:Collections

到您的源文件.

然后,您可以按如下方式迭代集合

for_each (begin(my_collection),end(my_collection),[&](my_collection_type^ value) {
          // code goes here...
});

注意:您可能还需要使用namespace std(for foree).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读