#include <string>
#include <set>
using namespace std;
class Node;
typedef set<Node, less<Node NodeSet;
// This code works.
// But when i use typedef set <Node, NodeCmpinstead, it will cause a
compile time error.
//error C2065: 'NodeCmp' : undeclared identifier.
// I don't know how can i use function objects here? For simply put the
NodeCmp before the
// typedef obviously causes error too.
// Notice that if i need a set which contains not Node object , but
just Node pointers,such as
// set<Node *>, using operators in the definition is impossible, for it
is not allowed to reload
// operators is impossible for object pointers.
// How can i define such a set?
//Best regards.
class Node {
private:
int m_i4Depth;
NodeSet m_Children;
public:
Node(string str):m_SearchKey(str) {
}
string m_SearchKey;
};
bool operator < (const Node &n1, const Node &n2)
{
cout << "^^" << endl;
return n1.m_SearchKey < n2.m_SearchKey;
}
struct NodeCmp: public binary_function<const Node &, const Node &,
bool{
bool operator () (const Node &n1, const Node &n2) const
{
return n1.m_SearchKey < n2.m_SearchKey;
}
};