fork(1) download
  1. #include <vector>
  2. #include <functional>
  3. #include <utility>
  4. #include <string>
  5. #include <iostream>
  6.  
  7. // cButton.h
  8. class cButton{
  9. private:
  10. const std::function<void()> effect;
  11. public:
  12. cButton(const std::function<void()>& effect);
  13. void onClick();
  14. };
  15.  
  16. // cButton.cpp
  17. cButton::cButton(const std::function<void()>& effect): effect(effect){}
  18.  
  19. void cButton::onClick(){
  20. if(effect) effect();
  21. }
  22.  
  23. class cMessage{
  24. public:
  25. cMessage(const std::vector<std::function<void()> >& effect);
  26. };
  27.  
  28. // cMessage.cpp
  29. cMessage::cMessage(const std::vector<std::function<void()> >& effect){
  30. for(unsigned int i = 0; i < effect.size(); i++)
  31. {
  32. cButton *b = new cButton(effect[i]);
  33. b->onClick();
  34. }
  35. }
  36.  
  37. int main(){
  38. const std::pair<const std::string, const unsigned int> var("test", 1);
  39. cMessage m ( {
  40. [var](){ std::cout << var.first << std::endl << var.second << std::endl; } } );
  41. return 0;}
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
test
1