【问题标题】:Cannot access Windows::UI::Xaml::Controls::ItemCollection.Size无法访问 Windows::UI::Xaml::Controls::ItemCollection.Size
【发布时间】:2020-04-11 21:36:00
【问题描述】:

如果这很明显,我对 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':返回'auto'的函数在定义之前不能使用

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

任何帮助将不胜感激

谢谢

【问题讨论】:

    标签: uwp c++17 winrt-xaml c++-winrt


    【解决方案1】:

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

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

    【讨论】:

    • Ahhhhhhhhh(用手拍打额头)。当然 - 非常感谢。我一直在努力解决这个问题,以为我对指针感到困惑(这是我的惯用伎俩)。再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 2019-07-01
    相关资源
    最近更新 更多