fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <functional>
  4.  
  5. class Object {
  6. std::function<void(int)> m_fTodo;
  7. public:
  8. template < typename Unary >
  9. Object( Unary const & unary )
  10. : m_fTodo( unary )
  11. {}
  12.  
  13. void TodoinClass() {
  14. m_fTodo( 10 );
  15. }
  16. };
  17.  
  18. class Scene
  19. {
  20. std::shared_ptr<Object> m_pObj;
  21. public:
  22. Scene()
  23. : m_pObj( new Object(std::bind(&Scene::Todo, this, std::placeholders::_1)) )
  24. {
  25. m_pObj->TodoinClass();
  26. }
  27.  
  28. void Todo(int A) {
  29. std::cout << "this: " << this << std::endl;;
  30. std::cout << "void Todo(" << A << ")" << std::endl;
  31. }
  32. };
  33.  
  34. int main() {
  35.  
  36. Scene scene;
  37.  
  38. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
this: 0xbfc3c7d8
void Todo(10)