【发布时间】:2012-04-07 04:01:51
【问题描述】:
我遇到了问题,我不确定我是否理解 STL 文档。假设我有这个:
#include <set>
...
struct foo
{
int bar;
};
struct comp
{
inline bool operator()(const foo& left,const foo& right)
{
return left.bar < right.bar;
}
};
int main()
{
std::set<foo,comp> fooset; // Uses comparison struct/class object comp to sort the container
...
return 0;
}
如何使用我自己的比较器结构将结构foos 插入set?
【问题讨论】:
-
您尝试使用
insert方法了吗?你得到了什么错误?