1. header file # include <functional>
2. Define the functor variable:
Std: tr1: function <T * (P1 *, P2 *)> DpdCreateT;
BCB can use typedef to declare a function.
Typedef T * (Delegate) (P1 *, P2 *);
Std: tr1: function <Delegate> DpdCreateT;
3. Connection:
Class Functions
Xx. DpdCreateT = std: tr1: bind (
& ZZZ: CreateConnection, // class function address
& Instance, // object instance address
Std: tr1: placeholders: _ 1, // placeholder for parameter 1
Std: tr1: placeholders: _ 2 // placeholder for parameter 1
);
Global function. assign a value directly.
Xx. DpdCreateT = GlobalCreateFunction;
//------------------------------------------------------------------------------
Simple function pointer
Typedef void (* FooPtr) (int, double );
Void Foo (int anInt, double aDouble)
{
Std: cout <"Foo () =" <anInt <"," <aDouble <endl;
}
FooPtr func = & Foo;
(* Func) (1, 2.0 );
//------------------------------------------------------------------------------
Member function pointer
Typedef int (SomeClass: * MemberFooPtr) (int, double );
MemberFooPtr p;
SomeClass SC;
P = & SomeClass: Foo;
(SC. * p) (1, 2 );
//-------------------------------------------------------------------------------
In VS 2008
# Include <functional>
Definition:
Typedef void (SetFrameValueActionDelegate) (T *, V frameValue );
Std: tr1: function <SetFrameValueActionDelegate> SetFrameValueAction;
Binding:
MWeekViewGroupLocationAnimation. SetFrameValueAction
=Std: tr1: bind(& MyClass: mWeekViewGroup_LocationAnimation_SetFrameValue,
& MRenderGroupWeekView,
Std: tr1: placeholders: _ 2);