fork download
  1. #include <iostream>
  2.  
  3. struct Obj
  4. {
  5. Obj* GetChild() const { return nullptr; }
  6. };
  7.  
  8. template <typename F>
  9. void DoWork(Obj* obj, int num, F&& func)
  10. {
  11. func(obj->GetChild());
  12. }
  13.  
  14. void foo(Obj*) { }
  15. void bar(const Obj*) { }
  16.  
  17. int main()
  18. {
  19. Obj obj;
  20. DoWork(&obj, 42, &foo);
  21. DoWork(&obj, 42, &bar);
  22. DoWork(&obj, 555, [](const Obj* o){ std::cout << o << std::endl; });
  23. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
0