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. void init (int x_in, int y_in, int z_in){
  16. this->x = x_in;
  17. this->y = y_in;
  18. this->z = z_in;
  19. }
  20.  
  21. int sum(){
  22. return this->x + this->y + this->z;
  23. }
  24.  
  25. void show_result() {
  26. int result = sum();
  27. cout << "sum = " << result << endl;
  28. }
  29. };
  30.  
  31. class B {
  32. public:
  33. A a;
  34. A b;
  35.  
  36. B() {
  37. a.init(0, 1, 2);
  38. b.init(1, 2, 3);
  39. }
  40. void show_all_result() {
  41. a.show_result();
  42. b.show_result();
  43. }
  44. };
  45.  
  46.  
  47. int main() {
  48.  
  49. B obj_B;
  50.  
  51. obj_B.show_all_result();
  52. }
  53.  
Success #stdin #stdout 0s 4492KB
stdin
Standard input is empty
stdout
sum = 3
sum = 6