fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Game;
  6. class Case
  7. {
  8. public:
  9. Case(Game& x);
  10. void functionWhichIsCalledWhenCaseIsPressed();
  11. private:
  12. Game &game;
  13. };
  14.  
  15. class Game
  16. {
  17.  
  18. public:
  19. Game();
  20. void doSomething();
  21. void test();
  22.  
  23. private:
  24. std::vector<Case> board;
  25. };
  26.  
  27. Case::Case(Game& x) : game(x){
  28. }
  29. void Case::functionWhichIsCalledWhenCaseIsPressed() {
  30. cout<<"Clicked"<<endl;
  31. game.doSomething();
  32. }
  33. Game::Game() {
  34. for (int i=0; i<10; i++)
  35. board.push_back(Case(*this));
  36. }
  37. void Game::doSomething() { cout<<"click on game"<<endl; }
  38. void Game::test() {
  39. board[3].functionWhichIsCalledWhenCaseIsPressed();
  40. }
  41.  
  42. int main() {
  43. Game g;
  44. g.test();
  45. return 0;
  46. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Clicked
click on game