Advertisement
NeraSnow

Untitled

Jun 29th, 2020
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class MyInt {
  6.     public:
  7.         int myInt;
  8.         int * space;
  9.         MyInt(int num) : myInt(num) {
  10.             cout << "Constructed!" << endl;
  11.             cout << "My address:" << this << endl;
  12.             space = new int;
  13.             *space = num;
  14.             cout << "space is newed!" << endl;
  15.         }
  16.         ~MyInt() {
  17.             cout << "Destroyed!" << endl;
  18.             cout << "My address:" << this << endl;
  19.             delete space;
  20.             cout << "space is deleted!" << endl;
  21.         }
  22.         MyInt plus1(MyInt n) {
  23.             MyInt newnum (n.myInt + 1);
  24.             cout << "I just constructed a new myInt" << endl;
  25.             return newnum;
  26.         }
  27.  
  28. };
  29.  
  30. int main() {
  31.     MyInt m1 (3);
  32.     cout << "Space after + 1: " << *(m1.plus1(m1)).space << endl;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement