IAsyncOperation返回指针或对Winrt类型的引用

时间:2019-01-08 10:30:58

标签: c++-winrt

  1. 我只能将IAsyncOperation仅用于值类型,而不能使用指针或引用IAsyncOperation IAsyncOperation。

基本上异步函数通过引用或指针返回值,方法是

Fail
IAsyncOperation<Buffer*> GetBufferAsync()
    {
        co_await 1500ms;
        return  mvo_buffer;

    }

Fail
IAsyncOperation<Buffer&> GetBufferAsync()
    {
        co_await 1500ms;
        return  mvo_buffer;

    }

Pass
Buffer* GetBuffer()
    {
        return &mvo_buffer;
    }

Pass
IAsyncOperation<Buffer> GetBufferAsync()
    {
        co_await 1500ms;
        return  mvo_buffer;

    }

谢谢

1 个答案:

答案 0 :(得分:1)

WinRT IAsyncOperation的类型必须是WinRT类型(没有限定符)。在您的示例中,假设Buffer是WinRT类型,则唯一可接受的形式是IAsyncOperation<Buffer>