Обратные вызовы в C++ | страница 42
>int capture = 10;
>auto lambda = [capture](int eventID) {/*this is a body of lambda*/};
>Initiator
>Initiator
>Initiator
>callbackLambda.setup(lambda); //Error: ‘operator’ = attempting to reference a deleted function
>callbackLambda.run();
4.4.3. Исполнитель
В Листинг 43 приведены примеры реализации исполнителя для различных типов аргументов. Объявления класса CallbackConverter представлены в Листинг 27 и Листинг 28 п. 4.2.2, инициатор используется из Листинг 41 п. 4.4.2.
>class Executor // (1)
>{
>public:
> static void staticCallbackHandler(int eventID, Executor* executor) {}
> void callbackHandler(int eventID) {}
> void operator() (int eventID) {}
>};
>void ExternalHandler(int eventID, void* somePointer) {} // (2)
>int main()
>{
> Executor executor; // (3)
> int capturedValue = 0;
> // (4) Pointer to the external function
> using PtrExtFunc = void(*) (int, void*); // (5)
> using CallbackExtFunction = CallbackConverter
> Initiator
> initExtFunction.setup(CallbackExtFunction(ExternalHandler, &executor)); // (8)
> // (9) Pointer to the static method
> using PtrStaticMethod = void(*) (int, Executor*); // (10)
> using CallbacStaticMethod = CallbackConverter
> Initiator
> initStaticMethod.setup(CallbacStaticMethod(Executor::staticCallbackHandler, &executor)); // (13)
> // (14) Pointer to the class member method
> using PtrMethod = void(Executor::*)(int); // (15)
> using CallbackMemberMethod = CallbackConverter
> Initiator
> initMemberMethod.setup(CallbackMemberMethod(&executor, &Executor::callbackHandler)); // (18)
> // (19) Functional object