在 C++ 环境中使用 PPL 任务时,我完全是个菜鸟,所以我很难弄清楚以下 C# 代码的 C++ 语法是什么:
private static async Task<RandomAccessStreamReference> GetImageStreamRef()
{
    return RandomAccessStreamReference.CreateFromStream(await GetImageStream());
}
private static async Task<IRandomAccessStream> GetImageStream()
{
    var stream = new InMemoryRandomAccessStream();
    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);
    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, width, height, 96, 96, imageBytes);
    await encoder.FlushAsync();
    return stream;
}
此 C# 代码取自Windows Store reversi Microsoft 示例代码。到目前为止,我能得到的最好的结果是:
Concurrency::task<IRandomAccessStream^> GetImageStream()
{
    auto stream = ref new InMemoryRandomAccessStream();
    task<BitmapEncoder^>(BitmapEncoder::CreateAsync(BitmapEncoder::JpegEncoderId, Stream)).then([this, stream, width, height, imageBytes](BitmapEncoder^ encoder)
    {
        encoder->SetPixelData(BitmapPixelFormat::Rgba8, BitmapAlphaMode::Ignore, width, height, 96.0, 96.0, imageBytes);
        return encoder->FlushAsync();
    }).then([this, stream]()
    {
        return stream; //Does this even make sense?
    });
    //return stream; //Not sure if I should have this here?
}
但它会产生以下编译错误:
error C4716: 'GetImageStream' : must return a value
我理解为什么会发生此错误,但我不知道如何拥有一个返回任务而在两个不同位置没有返回值的函数?我什至还没有处理 GetImageStream 。
我什至不确定我在这方面采取了正确的道路......
谢谢!