相关疑难解决方法(0)

无法插入到std :: map(G ++)

我有以下麻烦:

struct ServerPP {
    std::string name;
    int id;
    int expires;
};
std::map<std::string, std::set<ServerPP>> RemindTable;

int test(std::string email, ServerPP serv)
{
    RemindTable[email].insert(serv); // error when compile in this row below
}
Run Code Online (Sandbox Code Playgroud)

g ++中的错误:

In file included from /usr/include/c++/4.4/string:50,
                 from /usr/include/c++/4.4/bits/locale_classes.h:42,
                 from /usr/include/c++/4.4/bits/ios_base.h:43,
                 from /usr/include/c++/4.4/ios:43,
                 from /usr/include/c++/4.4/istream:40,
                 from /usr/include/c++/4.4/sstream:39,
                 from stdafx.h:19,
                 from ActiveReminder.cpp:4:
/usr/include/c++/4.4/bits/stl_function.h: In member function 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = ServerPP]':
/usr/include/c++/4.4/bits/stl_tree.h:1170:   instantiated from 'std::pair<typename std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(const …
Run Code Online (Sandbox Code Playgroud)

c++ g++ stdmap

3
推荐指数
1
解决办法
578
查看次数

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++ ×2

g++ ×1

set ×1

stdmap ×1

stl ×1