fork download
  1. #include <functional>
  2. #include <iostream>
  3.  
  4. class base {
  5. public:
  6. std::function<void()> Do;
  7. base() :Do(std::bind(&base::Do_impl, this)){}
  8. protected:
  9. base(std::function<void()> d) :Do(std::move(d)){}
  10. void Do_impl() const {std::cout << "base";}
  11. };
  12. class derived : public base{
  13. public:
  14. derived() :base(std::bind(&derived::Do_impl, this)){}
  15. protected:
  16. void Do_impl() const {std::cout << "derived";}
  17. };
  18.  
  19. int main() {
  20. derived d;
  21. d.Do();
  22. }
  23.  
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
derived