无论何时你建立指针的关联容器,注意你也得指定容器的比较类型。大多数时候,你的比较类型只是解引用
指针并比较所指向的对象(就像上面的StringPtrLess做的那样)。鉴于这种情况,你手头最好也能有一个用于
那种比较的仿函数模板。像这样:
struct DereferenceLess { template <typename PtrType> bool operator()(PtrType pT1, PtrType pT2) const // 参数是值传递的, { return *pT1 < *pT2; } }; set<string*, DereferenceLess> ssp; // 行为就像
关联容器--保存指针时要指定容器的比较类型---引用Effective STL
原文:http://www.cnblogs.com/jgliuhui1988/p/6236863.html