Advertisement
Guest User

Untitled

a guest
Aug 19th, 2015
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class CallBase {
  4. public:
  5.     virtual ~CallBase () {}
  6.  
  7.     template <typename F, typename... A>
  8.     void callBaseFunction (F func, A... args) {
  9.         func(args...);
  10.     }
  11. };
  12.  
  13. template<typename F>
  14. class Call : public CallBase {
  15. private:
  16.     F func;
  17.  
  18. public:
  19.     Call (F func) : func(func) {}
  20.  
  21.     ~Call () {}
  22.  
  23.     template <typename... A>
  24.     void call (A... args) {
  25.         callBaseFunction(func, args...);
  26.     }
  27. };
  28.  
  29. class Test {
  30. private:
  31.     CallBase* callBase;
  32.  
  33. public:
  34.     template<typename F, typename... A>
  35.     Test (F func, A... args) {
  36.         callBase = new Call<F>(func);
  37.  
  38.         ((Call<F>*)callBase)->call(args...);
  39.     }
  40.  
  41.     ~Test () {
  42.         delete callBase;
  43.     }
  44. };
  45.  
  46. void f (int a) {
  47.     std::cout << a << std::endl;
  48. }
  49.  
  50. int main () {
  51.     Test testA(f, 2);
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement