Effective STL 为包含指针的关联容器指定比较类型
2014-08-14 23:25
495 查看
// 为包含指针的关联容器指定比较类型.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <set> #include <string> #include <iostream> using namespace std; struct StringPtrLess: public binary_function<const string*, const string*, bool> { bool operator()(const string *ps1, const string *ps2) const { return *ps1 < *ps2; } }; typedef set<string*, StringPtrLess> StringPtrSet; StringPtrSet ssp; int main() { ssp.insert(new string("apple")); ssp.insert(new string("toy")); ssp.insert(new string("cat")); for (StringPtrSet::const_iterator i = ssp.begin();i != ssp.end();++i) { cout<<(**i)<<endl; } getchar(); return 0; }
相关文章推荐
- Effective STL 为包含指针的关联容器指定比较类型
- effective stl: 第20条,为包含指针的关联容器指定比较类型
- Effective STL 为包含指针的关联容器指定比较类型
- 为包含指针的关联容器指定比较类型
- 为包含指针的关联容器指定比较类型
- 为包含指针的关联容器指定比较类型
- 条款20:为指针的关联容器指定比较类型——effective STL
- 条款20:为指针的关联容器指定比较类型
- 为指针的关联容器指定比较类型
- 为指针的关联容器指定比较类型
- 使用STL的经验总结_指定关联容器的比较类型_12
- Effective STL - 为指针的关联容器指定比较函数
- Effective STL 条款21: 关联容器的strict weak order(让比较函数对相等的值返回false)
- Effective STL 条款21: 关联容器的strict weak order(让比较函数对相等的值返回false)
- Effective STL 条款21: 关联容器的strict weak order(让比较函数对相等的值返回false)
- effective stl 第33条:对包含指针的容器使用remove这一类算法时要特别小心
- Effective STL 条款21: 关联容器的strict weak order(让比较函数对相等的值返回false)
- Effective STL 条款21: 关联容器的strict weak order(让比较函数对相等的值返回false) .
- Effective STL 第7条:如果容器中包含了通过new操作创建的指针,切记在容器对象析构前将指针delete掉
- 关联容器存放的是指针时,自定义比较函数模板