fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. class Parent
  5. {
  6. private:
  7. std::function<const std::string(const std::string &)> m_func;
  8. public:
  9. //Parent();
  10. Parent(std::function<const std::string(const std::string &)> func) {
  11. m_func = func;
  12. };
  13.  
  14. std::string Execute() {
  15. return m_func("do it ");
  16. };
  17. };
  18. class Child : public Parent
  19. {
  20. public:
  21. Child():Parent( std::bind(&Child::hoge, this, std::placeholders::_1)){};
  22. const std::string hoge(const std::string &str) {
  23. return str + " you sould... may be can!";
  24. };
  25. };
  26.  
  27. int main() {
  28. Child cld;
  29. std::cout << cld.Execute() << std::endl;
  30. return 0;
  31. }
Success #stdin #stdout 0s 4172KB
stdin
Standard input is empty
stdout
do it  you sould... may be can!