Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class CallBase {
- public:
- virtual ~CallBase () {}
- virtual void call () = 0;
- };
- template<typename F, typename A>
- class Call : public CallBase {
- private:
- F func;
- A args;
- public:
- Call (F func, A args) : func(func), args(args) {}
- ~Call () {}
- void call () {
- func(args);
- }
- };
- class Test {
- private:
- CallBase* call;
- public:
- template<typename F, typename... A>
- Test (F func, A... args) {
- this->call = new Call<F, A...>(func, args...);
- }
- ~Test () {
- delete call;
- }
- void callFunction () {
- call->call();
- }
- };
- void f (int a) {
- std::cout << a << std::endl;
- }
- int main () {
- Test test(f, 2);
- test.callFunction();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement