小编And*_*uer的帖子

C++设置容器的问题

当我尝试编译以下代码时:

    #include <iostream>
    #include <set>
    #include <vector>

    using namespace std;

    template <class T, class S> 
    class Property
    {
    public:
        pair<T,S> p;

        Property(T t, S s) { p = make_pair(t,s);}

    };

    int main()
    {
    set< Property<string, string> > properties;
    Property<string, string> name("name", "Andy");

    properties.insert(name);

    }
Run Code Online (Sandbox Code Playgroud)

我收到编译错误。但是,当我用向量替换 set 并因此使用 push_back 函数而不是 insert 函数时,一切正常。谁能解释一下我做错了什么?谢谢指教。

c++ stl set

0
推荐指数
1
解决办法
1695
查看次数

标签 统计

c++ ×1

set ×1

stl ×1