【问题标题】:Using a vector of structs in a struct in c++/cx在 c++/cx 的结构中使用结构向量
【发布时间】:2012-08-02 10:52:28
【问题描述】:

我有一个头文件定义了一些我想在我的代码中使用的结构。

public value struct HttpHeader
{
   Platform::String^ mName;
   Platform::String^ mValue;

};
typedef Platform::Collections::Vector<HttpHeader> HttpHeaders;

public value struct HttpRequestEvent
{
   Platform::String^ mUri;
   HttpHeaders^ mHeaders;
};

当我构建这个时,我得到了这个错误:

error C3986: 'mHeaders': signature of public member contains native type 'std::equal_to<_Ty>'
      with
      [
          _Ty=cpcpb::HttpHeader
      ] (SettingsServiceImpl.cpp)

我在这里缺少什么?我不都是用 C++/Cx 吗?

【问题讨论】:

    标签: windows-runtime c++-cx


    【解决方案1】:

    使用Windows::Foundation::Collections::IVector 而不是Platform::Collections::Vector

    要使用Platform::Collections::Vector,您必须提供一个自定义比较器,即等于运算符。

    检查此链接 - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/5ec2090f-b7e6-40e8-9cd7-75cf36d05ab3/

    【讨论】:

    • 此外,在 C++/Cx 中,值类型(值结构/值类)应该只包含基本类型、String^ 和其他值类型。其他类型是不允许的(至少在 RTM 编译器中,早期版本的编译器可能错误地允许这样做)。
    • 所以因为 IVector 不是基本类型,所以我的 HttpRequestEvent 结构是不允许的。那么有没有办法在值结构中包含一个向量?
    • 我不相信有办法做到这一点。您是否有理由无法将 HttpReqeustEvent 设为 ref struct/class?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 2012-10-16
    • 2015-12-18
    • 2017-12-03
    • 2013-08-14
    • 2018-09-10
    相关资源
    最近更新 更多