【问题标题】:WinRT C++/CX Tasks not compilingWinRT C++/CX 任务未编译
【发布时间】:2013-01-01 20:17:57
【问题描述】:

我正在尝试使用 C++/CX 创建 WinRT 组件。我有以下代码,但无法编译。它有什么问题? 据我了解,如果 PPL 任务是有结果的任务,则应透明地将其转换为 IAsyncOperation。

IAsyncOperation<Boolean>^ Class::OpAsync()
{
    return create_task([] () { return true; });
}

错误信息

error C2440: 'return' : cannot convert from 'Concurrency::task<_ReturnType>' to 'Windows::Foundation::IAsyncOperation<TResult> ^'
          with
          [
              _ReturnType=bool
          ]
          and
          [
              TResult=bool
          ]
          No user-defined-conversion operator available, or
          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

【问题讨论】:

    标签: windows-runtime task c++-cx ppl iasyncoperation


    【解决方案1】:

    create_task() 函数用于获取 IAsyncOperation 并将其转换为任务(基本上与您想要的相反)。

    要将任务转换为 IAsyncOperation,您需要改为调用 create_async()。

    【讨论】:

      猜你喜欢
      • 2011-11-25
      • 1970-01-01
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-17
      • 2018-08-12
      • 1970-01-01
      • 2020-06-02
      相关资源
      最近更新 更多