首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自cppreference.com的示例不使用MSVC进行编译。

来自cppreference.com的示例不使用MSVC进行编译。
EN

Stack Overflow用户
提问于 2022-02-09 05:44:51
回答 1查看 117关注 0票数 1

尝试从cppreference.com编译以下示例

代码语言:javascript
复制
#include <coroutine>

struct promise;
struct coroutine : std::coroutine_handle<promise>
{
    using promise_type = struct promise;
};

struct promise {
    coroutine get_return_object()
    {
        return { coroutine::from_promise(*this) };
    }
    std::suspend_always initial_suspend() noexcept { return {}; }
    std::suspend_never final_suspend() noexcept { return {}; }
    void return_void() {}
    void unhandled_exception() {}
};

struct S {
    int i;
    coroutine f() {
        std::cout << i;
        co_return;
    }
};

但编译错误:

代码语言:javascript
复制
error C3789: this function cannot be a coroutine: 'coroutine::promise' does not declare the member 'get_return_object()'

编译器: MSVC2019,/std:c++latest

微软(R) C/C++优化编译器版本19.29.30137用于x86

但是GCC12编译它,MSVC有什么问题吗?

EDIT1

与MSVC2022相同的错误

为x86优化编译器版本19.30.30709

/std:c++latest

EN

回答 1

Stack Overflow用户

发布于 2022-02-09 09:52:35

正如该网站所述:

工作正在进行中:这个页面正在进行更新,以反映C++20工作草案中包含的Coroutines技术规范的各个部分。

此示例不能使用MSVC2019编译器运行。您可以使用此版本安装并试用该版本:

https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71044540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档