您的位置:首页 > Web前端

Effective STL 为包含指针的关联容器指定比较类型

2014-08-14 23:25 274 查看
// 为包含指针的关联容器指定比较类型.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;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: