无法访问 Windows::UI::Xaml::Controls::ItemCollection.Size

Cannot access Windows::UI::Xaml::Controls::ItemCollection.Size

我是 C++ 的新手,很抱歉,如果这很明显,但我无法访问 Windows::UI::Xaml::Controls::ItemCollection.

类型的 属性 'Size'

这是我的代码:

Windows::UI::Xaml::Controls::ItemCollection& items = Items(); // Items in a property of Windows::UI::Xaml::Controls::GridView which my class derives from
auto count = items.Size(); // -> build error

错误是'winrt::impl::consume_Windows_Foundation_Collections_IVector::Size':returns'auto'定义前不能使用的函数

我知道 ItemCollection 有一个大小 属性,为什么编译器抱怨它没有定义。

任何帮助将不胜感激

谢谢

您忘记包含提供模板定义的头文件,可能 <winrt/Windows.Foundation.Collections.h。这个特殊的编译器错误曾经是一个链接器错误,很难解释。

Raymond Chen 在博客中介绍了 C++/WinRT 中的更改 'promote' 此链接器错误变为编译器错误:Why does my C++/WinRT project get errors of the form “consume_Something: function that returns ‘auto’ cannot be used before it is defined”?