fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4.  
  5. typedef unsigned GLuint;
  6.  
  7. class A {
  8.  
  9. public:
  10. void Draw(GLuint shader) {
  11. std::cout << "A " << shader << std::endl;
  12. //делаем что-то
  13. }
  14. };
  15.  
  16. class B {
  17. public:
  18.  
  19. void Draw(GLuint shader) {
  20. std::cout << "B " << shader << std::endl;
  21. //делаем что-то не тоже что в class A;
  22. }
  23. };
  24.  
  25. class mainClass {
  26.  
  27. public:
  28. std::function<void (GLuint)> draw;
  29. };
  30.  
  31.  
  32. int main() {
  33. using namespace std::placeholders;
  34.  
  35. mainClass m;
  36. A a;
  37. B b;
  38.  
  39. m.draw = std::bind(&A::Draw, a, _1);
  40. m.draw(1);
  41.  
  42. m.draw = std::bind(&B::Draw, b, _1);
  43. m.draw(2);
  44. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
A 1
B 2