小编Dan*_* G.的帖子

当T在命名空间中时,在std :: vector <std :: reference_wrapper <T >>上的std :: find失败,错误为“'operator =='不匹配”错误

我目前正在从事大型代码项目,并希望借此机会学习和使用名称空间。我定义的所有类都驻留在单个名称空间Test中。

我的一个类(在这里称为Thing)具有唯一的ID。我需要能够保存对某些事物的引用的std :: vector,因此我正在使用std :: reference_wrappers。在程序中的某些点,我需要从向量中删除某些std :: reference_wrappers,所以我使用std :: find:

#include <algorithm>
#include <functional>
#include <vector>

namespace Test {

class Thing {
private:
    const int id;

public:
    Thing(int id);
    const int ID() const;
};

}

Test::Thing::Thing(int id) : id(id) { }

const int Test::Thing::ID() const {
    return id;
}

inline bool operator==(const Test::Thing& lhs, const Test::Thing& rhs) {
    return lhs.ID() == rhs.ID();
}
inline bool operator!=(const Test::Thing& lhs, const Test::Thing& rhs) {
    return !(lhs == rhs);
}

int main() { …
Run Code Online (Sandbox Code Playgroud)

c++ namespaces vector reference-wrapper

2
推荐指数
1
解决办法
62
查看次数

标签 统计

c++ ×1

namespaces ×1

reference-wrapper ×1

vector ×1