1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
#include <iostream>

class X {
   public:
      X() : data(new int{0}) {
	 std::cout << "X: default constructor" << std::endl;
      }
      X(int i) : data(new int{i}) {
	 std::cout << "X: constructor with i = " << i << std::endl;
      }
      X(const X& other) : data(new int{*other.data}) {
	 std::cout << "X: copy constructor with *other.data = "
	    << *other.data << std::endl;
      }
      ~X() {
	 std::cout << "X: destructor with *data = " << *data << std::endl;
	 delete data;
      }
      X& operator=(const X& other) {
	 std::cout << "X: assignment operator with *other.data = "
	    << *other.data << std::endl;
	 *data = *other.data;
	 return *this;
      }
   private:
      int* data;
};

int main() {
   X x1{42};
   X x2 = x1;
   X x3; x3 = x1;
}