Closed bethebest0622 closed 6 months ago
The Warning Message is:
this function cannot be a coroutine: 'std::coroutine_traits<Promise>' has no member named 'promise_type'
here is my code:
#include <iostream> #include <coroutine> struct Awaiter { bool await_ready() { std::cout << "await ready or not" << std::endl; return true; } void await_resume() { std::cout << "await resumed" << std::endl; } void await_suspend(std::coroutine_handle<> h) { std::cout << "await suspended" << std::endl; } }; struct Promise { struct promise_type { auto get_return_object() noexcept { std::cout << "get return object" << std::endl; return Promise(); } auto initial_suspend() noexcept { std::cout << "initial suspend, return never" << std::endl; return std::suspend_never{}; } auto final_suspend() noexcept { std::cout << "final suspend, return never" << std::endl; return std::suspend_never{}; } void unhandled_exception() { std::cout << "unhandle exception" << std::endl; std::terminate(); } void return_void() { std::cout << "return void" << std::endl; return; } }; }; Promise CoroutineFunc() { // here is the warning place !!!!!!!!!! std::cout << "before co_await" << std::endl; co_await Awaiter(); std::cout << "after co_await" << std::endl; } int main() { std::cout << "" << std::endl; CoroutineFunc(); std::cout << "main() exit" << std::endl; }
I think there is promise_typein Promise, could you help on this?
promise_type
Promise
Please see CONTRIBUTING.md
The Warning Message is:
this function cannot be a coroutine: 'std::coroutine_traits<Promise>' has no member named 'promise_type'
here is my code:
I think there is
promise_type
inPromise
, could you help on this?