int main() { // Lambda auto Func2 = [] (int a, int b) -> int { return a + b; }; // Simplify function type using func_type = int(int, int); // Store callable objects in function objects std::cout << "Call function as stand alone :\n"; std::function<func_type> f0 = Func0(); std::cout << f0(9, 7) << std::endl; std::function<func_type> f1(Func1); std::cout << f1(4, 6) << std::endl; std::function<func_type> f2(Func2); std::cout << f2(4, 7) << std::endl; // Store in container holding functions of type T std::vector<std::function<func_type>> tbl; tbl.push_back(f0); tbl.push_back(f1); tbl.push_back(f2); std::cout << "Call function from tbl :\n"; int val1(4), val2(8); for(std::function<func_type> func : tbl) std::cout << func(4, 8) << std::endl; return 0; }
EmulateClass(vpnes::CClock *pClock, int *pFlag) { vpnes::SEvent *NewEvent; CurT = 0; Flag = pFlag; Clock = pClock; memset(LocalEvents, 0, sizeof(vpnes::SEventData) * MAX_EVENTS); NewEvent = new vpnes::SEvent; NewEvent->Data = &LocalEvents[EVENT_FUNC0]; NewEvent->Execute = [this]{Func0();}; EventChain[EVENT_FUNC0] = NewEvent; Clock->RegisterEvent(NewEvent); NewEvent = new vpnes::SEvent; NewEvent->Data = &LocalEvents[EVENT_FUNC1]; NewEvent->Execute = [this]{Func1();}; Clock->RegisterEvent(NewEvent); EventChain[EVENT_FUNC1] = NewEvent; Clock->EnableEvent(EventChain[EVENT_FUNC0]); Clock->EnableEvent(EventChain[EVENT_FUNC1]); Clock->SetEventTime(EventChain[EVENT_FUNC0], EventTime1); Clock->SetEventTime(EventChain[EVENT_FUNC1], EventTime2); }