You can use std :: function to save the called and subsequent call.
class X { public: void set(std::function<void()> f) { callable = f; } void call() const { callable(); } private: std::function<void()> callable; }; void f() { std::cout << "Meow" << std::endl; }
Then create an instance of X and install the called:
X x; x.set(f);
Call the saved caller later:
x.call();
Edgar rokjΔn
source share