fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class A{
  6. public:
  7. int x, y, z;
  8.  
  9. A() {
  10. this->x = 0;
  11. this->y = 0;
  12. this->z = 0;
  13. }
  14.  
  15. ~A() { }
  16.  
  17. void init (int x_in, int y_in, int z_in){
  18. this->x = x_in;
  19. this->y = y_in;
  20. this->z = z_in;
  21. }
  22.  
  23. int sum(){
  24. return this->x + this->y + this->z;
  25. }
  26.  
  27. void show_result() {
  28. int result = sum();
  29. cout << "sum = " << result << endl;
  30. }
  31. };
  32.  
  33.  
  34. enum { A_CAR, A_CAT, A_CANADA, A_NUM };
  35.  
  36. class B {
  37. public:
  38. A A_arr[A_NUM];
  39.  
  40. B() {
  41. A_arr[A_CAR].init(0, 1, 2);
  42. A_arr[A_CAT].init(1, 2, 3);
  43. A_arr[A_CANADA].init(8, 7, 6);
  44. }
  45.  
  46. ~B() {}
  47.  
  48. void show_all_result() {
  49. for (int i = 0; i < A_NUM; i++) {
  50. A_arr[i].show_result();
  51. }
  52. }
  53. };
  54.  
  55.  
  56. int main() {
  57.  
  58. B obj_B;
  59.  
  60. obj_B.show_all_result();
  61. }
  62.  
Success #stdin #stdout 0s 4376KB
stdin
Standard input is empty
stdout
sum = 3
sum = 6
sum = 21