在我的 C++/WinRT 项目中,我试图在 UI 线程上运行一些代码,但收到一条错误消息:
“winrt::impl::consume_Windows_UI_Core_ICoreDispatcher<winrt::Windows::UI::Core::ICoreDispatcher>::RunAsync':在定义之前不能使用返回'auto'的函数”
我正在调用这样的方法:
Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [=]()
{
// Code to be executed.
});
Run Code Online (Sandbox Code Playgroud)
该实现来自自动生成的 winrt 文件,该文件auto作为返回类型返回。
template <typename D>
struct consume_Windows_UI_Core_ICoreDispatcher
{
[[nodiscard]] auto HasThreadAccess() const;
auto ProcessEvents(Windows::UI::Core::CoreProcessEventsOption const& options) const;
auto RunAsync(Windows::UI::Core::CoreDispatcherPriority const& priority, Windows::UI::Core::DispatchedHandler const& agileCallback) const;
auto RunIdleAsync(Windows::UI::Core::IdleDispatchedHandler const& agileCallback) const;
};
Run Code Online (Sandbox Code Playgroud)
有什么我遗漏的还是这是一个错误?
这是对C++/WinRT 库进行了相当新的添加的结果。在生成的文件中使用返回类型推导会将用于触发链接器错误的内容转换为编译器错误。由于以下几个原因,编译器错误是有利的:
错误诊断的原因是#include头文件缺少包含相关类型的完整定义的指令。识别丢失的包含通常很简单。错误消息包括缺少的类型名称,采用以下形式
winrt::impl::consume_ <namespace1> _ <namespace2> _..._ <some_interface>
相应的头文件位于winrt目录下,其名称是以点分隔的命名空间串联,后跟.h.
在这种情况下,缺少的类型是
winrt::impl::consume_Windows_UI_Core_ICoreDispatcher<winrt::Windows::UI::Core::ICoreDispatcher>
所以你需要#include <winrt/Windows.UI.Core.h>进入使用该ICoreDispatcher接口的编译单元。
Raymond Chen 在其题为“为什么我的 C++/WinRT 项目为什么我的 C++/WinRT 项目会得到“consume_Something: 函数在定义之前不能使用返回‘auto’的错误”的博客文章中有关于该主题的更多背景信息?.
| 归档时间: |
|
| 查看次数: |
1015 次 |
| 最近记录: |