#include <iostream>
using namespace std;

class smartptr
{
   private:
     int *ptr;

   public:
     smartptr(int *val=nullptr) : ptr(val){
         cout<<"inside constructor\n";
     }

     ~smartptr()
      {
        cout<<"Inside destructor\n";
        delete ptr;
      }

     int operator*()
      {
        return *ptr;
      }


};



int main() {

    int *a=new int(18);
    smartptr obj(a);

    cout<<*obj<<endl;
    
    return 0;
}

Embed on website

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