35657

Untitled

Feb 17th, 2024
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Class1 {
  6.     int fieldOne;
  7.     int fieldTwo;
  8. public:
  9.     Class1(int param) : fieldOne{ param + 10 }, fieldTwo{ param } {}
  10.     void print() {
  11.         cout << "fieldOne = " << fieldOne << '\n' << "fieldTwo = " << fieldTwo << '\n';
  12.     }
  13. };
  14.  
  15. class Class2 {
  16.     int fieldOne;
  17.     int fieldTwo;
  18. public:
  19.     Class2(int param) : fieldTwo{ param }, fieldOne{ fieldTwo + 10 } {}
  20.     void print() {
  21.         cout << "fieldOne = " << fieldOne << '\n' << "fieldTwo = " << fieldTwo << '\n';
  22.     }
  23. };
  24.  
  25.  
  26. int main() {
  27.  
  28.     cout << "Class1\n";
  29.     Class1 t2{ 33 };
  30.     t2.print();
  31.  
  32.     cout << "Class2\n";
  33.     Class2 t1{ 42 };
  34.     t1.print();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment