如何在C ++中为具有成员集<class *>的类定义比较函数

时间:2019-04-28 20:34:21

标签: c++ stl set operator-overloading

我想实现一个TrieNode类,该类包含一组TrieNode指针,并且它的值是一个int。如何定义节点集的比较?

MySetTrieNode.h

class MySetTrieNode {
public:
    int character;
    std::set<MySetTrieNode *> *nodes;
public:
    bool operator<(MySetTrieNode other) const;
};

MySetTrieNode.cpp

MySetTrieNode::MySetTrieNode() {
    this->character = -1;
    nodes = new std::set<MySetTrieNode *>();
}

bool MySetTrieNode::operator<(const MySetTrieNode other) const {
    return this->character < other.character;
}

0 个答案:

没有答案