axeefectushka

Untitled

Jan 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. Пример. Класс с вложенным конструктором
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. class Cls01
  6. {
  7. int *a;
  8. double *b;
  9. public:
  10. Cls01 (int p1, double p2)
  11. {
  12. a=new int (p1);
  13. b=new double (p2);
  14. }
  15. ~Cls01()
  16. {
  17. delete a; cout<<"Delete a"<<endl;
  18. delete b; cout<<"Delete b"<<endl;
  19. }
  20. void out_ab()
  21. {
  22. cout<<"a="<<*a<<"b="<<*b<<endl;
  23. }
  24. };
  25.  
  26. class Cls02
  27. {
  28. Cls01 x,y;
  29. public:
  30. Cls02 (int, double, int, double);
  31. void out_xy()
  32. {
  33. x.out_ab();
  34. y.out_ab();
  35. }
  36. };
  37.  
  38. Cls02::Cls02 (int l1, double l2, int l3, double l4): x (l1, l2), y (l3,l4)
  39. {
  40. }
  41.  
  42. void main()
  43. {
  44. Cls02 s(10, 1.2, 20, 2.5);
  45. s.out_xy();
  46. }
Add Comment
Please, Sign In to add comment