fork download
  1. #include <iostream>
  2.  
  3. template <typename T>
  4. class my_auto_ptr
  5. {
  6. public:
  7. my_auto_ptr(T* xx = nullptr) { x = xx; }
  8. ~my_auto_ptr() { delete x; }
  9.  
  10. T& operator*() { return *x; }
  11.  
  12. private:
  13. T* x;
  14. };
  15.  
  16. int main()
  17. {
  18. my_auto_ptr<bool> pb (new bool(false));
  19. my_auto_ptr<int> pi (new int(42));
  20. my_auto_ptr<float> pf (new float(0.0));
  21.  
  22. *pb = true;
  23. *pi = 43;
  24. *pf = 3.14f;
  25.  
  26. std::cout << std::boolalpha << *pb << '\n';
  27. std::cout << *pi << '\n';
  28. std::cout << *pf << '\n';
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
true
43
3.14