当我尝试编译以下代码时:
#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 函数时,一切正常。谁能解释一下我做错了什么?谢谢指教。