fork(1) download
  1. #include <functional>
  2.  
  3. using FPTR = std::function<int(int)>;
  4.  
  5. class A {
  6. public:
  7. FPTR worker;
  8. int i;
  9. A(int x) { i = x; }
  10. };
  11.  
  12. template <class BASE>
  13. class C : public BASE {
  14. public:
  15. C(int y) : BASE(y) {
  16. this->worker = std::bind(&C<BASE>::doit, this, y);
  17. }
  18. int doit(int z) { return this->i + z; }
  19. int doit_different(int z) { return this->i - z; }
  20. };
  21.  
  22. int main() {
  23. C<A> instance(66);
  24. instance.worker(5);
  25. return 0;
  26. }
Success #stdin #stdout 0s 4388KB
stdin
Standard input is empty
stdout
Standard output is empty