fork(2) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. class A {
  11. public:
  12. static vector<A*> A_vector;
  13. int x, y, z;
  14.  
  15. A() {
  16. this->x = 0;
  17. this->y = 0;
  18. this->z = 0;
  19. A_vector.push_back(this);
  20. }
  21.  
  22. ~A() { }
  23.  
  24. void init(int x_in, int y_in, int z_in) {
  25. this->x = x_in;
  26. this->y = y_in;
  27. this->z = z_in;
  28. }
  29.  
  30. int sum() {
  31. return this->x + this->y + this->z;
  32. }
  33.  
  34. void show_result() {
  35. int result = sum();
  36. cout << "sum = " << result << endl;
  37. }
  38. };
  39. vector<A*> A::A_vector;
  40.  
  41.  
  42. class B {
  43. public:
  44. A A_car, A_cat, A_canada;
  45.  
  46. B() {
  47. A_car.init(0, 1, 2);
  48. A_cat.init(1, 2, 3);
  49. A_canada.init(8, 7, 6);
  50. }
  51.  
  52. ~B() {}
  53.  
  54. void show_all_result() {
  55. for (int i = 0; i < A::A_vector.size(); i++)
  56. A::A_vector[i]->show_result();
  57. }
  58. };
  59.  
  60.  
  61. int main() {
  62.  
  63. B obj_B;
  64.  
  65. obj_B.show_all_result();
  66. printf("done\n");
  67. return 0;
  68. }
  69.  
  70.  
Success #stdin #stdout 0s 4408KB
stdin
Standard input is empty
stdout
sum = 3
sum = 6
sum = 21
done