分类: C/C++
2015-02-25 15:57:49
typedef void (*PFT) ( char ,int ); void bar(char ch, int i) { cout<<"bar "<<ch<<' '<<i<<endl; return ; } PFT pft; pft = bar; pft('e',91);
typedef void (*PFT) ( char ,int ); void bar(char ch, int i) { cout<<"bar "<<ch<<' '<<i<<endl; return ; } void foo(char ch, int i, PFT pf) { pf(ch,i); return ; } PFT pft; pft = bar; foo('e',12,pft);
class A{ public: int operator()(int x){return x;} }; A a; a(5);
class Func{ public: int operator() (int a, int b) { cout<<a<<'+'<<b<<'='<<a+b<<endl; return a; } }; int addFunc(int a, int b, Func& func) { func(a,b); return a; } Func func; addFunc(1,3,func);
class FuncT{ public: template<typename T> T operator() (T t1, T t2) { cout<<t1<<'+'<<t2<<'='<<t1+t2<<endl; return t1; } }; template <typename T> T addFuncT(T t1, T t2, FuncT& funct) { funct(t1,t2); return t1; } FuncT funct; addFuncT(2,4,funct); addFuncT(1.4,2.3,funct);