- 注册时间
 - 2009-2-12
 
- 最后登录
 - 1970-1-1
 
- 威望
 -  星
 
- 金币
 -  枚
 
- 贡献
 -  分
 
- 经验
 -  点
 
- 鲜花
 -  朵
 
- 魅力
 -  点
 
- 上传
 -  次
 
- 下载
 -  次
 
- 积分
 - 27613
 
- 在线时间
 -  小时
 
 
 
 
 
 
 | 
 
 楼主 |
发表于 2010-8-5 14:37:08
|
显示全部楼层
 
 
 
 21# wayne 
写了一个 Demo code:- #include <iostream>
 - #include <algorithm>
 - #include <vector>
 - #include <tr1/functional> 
 - using std::tr1::placeholders::_1; 
 - 
 - //normal function
 - void foo(int i) { std::cout<<"Foo\t"<<i<<std::endl; }
 - //class object with operator()
 - class Bar{	
 - public:
 -     void operator () (int i) { std::cout<<"Bar\t"<< i<<std::endl; }
 - };
 - //member function 
 - class Ctest {
 - public:
 -     void puts(std::string &s) {std::cout<<"STRING:\t"<<s<<std::endl;}
 -     void puts(double x) {std::cout <<"DOUBLE:\t"<<x<<std::endl;}
 - };
 - 
 - int main(){
 - Bar bar;Ctest fm;
 - std::tr1::function<void (int)> f(&foo); f(2009);
 - std::tr1::function<void (int)> b=bar;   b(2010);
 - 
 - double a[7] = { .8, .7, .9, .5, .3};
 - std::vector<double> v(a,a+5);
 - sort(v.begin(),v.end());
 - void (Ctest::*fn)(double) = &Ctest::puts;
 - std::for_each(v.begin(), v.end(), std::tr1::bind(fn, fm, _1)); 
 - }
 
  复制代码 |   
 
 
 
 |