KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I was wondering if this would be an accepted approach to writing callbacks: Storing callbacks: struct EventHolder { std::function<void()> Callback; EventTypes::EventType Type; }; std::vector<Events::EventHolder> EventCallbacks; Method definition: void On(EventType OnEventType,std::function<void()>&& Callback) { Events::EventHolder NewEvent; NewEvent.Callback=std::move(Callback); NewEvent.Type=OnEventType; EventCallbacks.push_back(std::move(NewEvent)); } Binding event: Button->On(EventType::Click,[]{ // ... callback body }); My biggest question would be regarding passing the Callback by value. Is this a valid approach?
Tags (comma-separated)
Save Edits
Cancel