#include <iostream>
using namespace std;

class Temp
{
   private:
      int *x;

   public:
     Temp(int m)    //PARAMETERIZED CONSTRUCTOR
     {
        x=new int;
         *x=m;
     }

    //Shallow copy calls own copy contructor

     Temp(const Temp &t)    //Deep copy
     {
        x=new int;
        *x=t.getx();
     }


     int getx() const
     {
       return *x;
     }

     void setx(int m)
     {
         *x=m;
     }

     void show()
     {
        cout<<"The value of x is : "<<*x<<endl;
     }   

};


int main() {

    Temp t1(10);
    Temp t2(t1);
    t1.show();
    t2.show();
    t2.setx(12);
    t1.show();
    t2.show();
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: