2013-01-18 67 views
0

我想用C++/CX創建一個WinRT組件。我有以下代碼,它不會編譯。它有什麼問題? 從我所瞭解的PPL任務應該透明地轉換爲IAsyncOperation如果它是一個任務與結果。WinRT C++/CX任務不編譯

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 

回答

3

的create_task()函數是用於拍攝IAsyncOperation並把它變成一個任務(基本上,你想要什麼樣的反向)。

要將任務轉換爲IAsyncOperation,您需要調用create_async()。