【问题标题】:Error related to headers and namespaces when migrating from C++/CX to C++/WinRT从 C++/CX 迁移到 C++/WinRT 时与标头和命名空间相关的错误
【发布时间】:2020-08-04 22:16:16
【问题描述】:

文件.h:

std::map<winrt::hstring, winrt::hstring> someMap;

文件.cpp

auto it = someMap.find(someKey);
if (it != someMap.end()) {
    it.second += (winrt::hstring{L", "} + someString.c_str());
}

我收到以下错误:

'second': is not a member of 'std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>'
    with
    [
        _Ty=std::pair<winrt::hstring,winrt::hstring>
    ]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\include\xtree(778): note: see declaration of 'std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>>'
    with
    [
        _Ty=std::pair<winrt::hstring,winrt::hstring>
    ]

我从here 知道需要包含我们使用的每个命名空间的标头。我假设这个错误来自那里,也许这就是为什么 Visual Studio 无法解析来自 std::map 的查找,而是映射到来自 xtree.h 的查找。但我可能错了。我确实尝试将 std 作为命名空间,但这似乎不起作用,或者至少看起来我可能需要除此之外的东西。我应该包含哪些标头和/或命名空间才能解决此错误。

【问题讨论】:

    标签: c++ windows windows-runtime cppwinrt


    【解决方案1】:

    std::map::find 返回一个迭代器。与地图的实际项目不同,迭代器没有 firstsecond 成员。如果要访问该项目,则需要使用 *-&gt; 运算符取消对迭代器的引用:

    auto it = someMap.find(someKey);
    if (it != someMap.end()) {
        it->second += (winrt::hstring{L", "} + someString.c_str());
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2011-11-25
      • 1970-01-01
      • 2014-10-18
      相关资源
      最近更新 更多