小编Sin*_*ndi的帖子

std :: set有重复的条目

我有一组3个整数的元组,我不想要任何重复.也就是说,我不希望2个条目具有相同的3个值.

这是我的代码.

struct Key{
    unsigned a;
    unsigned b;
    unsigned c;
  public:
    Key(unsigned _a, unsigned _b, unsigned _c) :
        a(_a),
        b(_b),
        c(_c) {}
    bool operator<(const Key& rhs) const
    {
        if (a < rhs.a) {
            return true;
        }
        if (b < rhs.b) {
            return true;
        }
        if (c < rhs.c) {
            return true;
        }
        return false;
    };
};
std::set<Key> myset;
Run Code Online (Sandbox Code Playgroud)

但我myset有时会看到重复.我无法准确捕捉到什么序列导致添加重复条目.它并不总是发生.我的问题是,我的operator<功能有什么本质上的错误吗?

c++ stl

14
推荐指数
2
解决办法
2204
查看次数

标签 统计

c++ ×1

stl ×1