Guest User

Untitled

a guest
May 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. using std::cout;
  3. using std::endl;
  4.  
  5. template <typename T> class New {
  6. T* mPtr;
  7. public:
  8. New() : mPtr(new T()) {}
  9. operator T*() { return mPtr; }
  10. T* operator->() { return mPtr; }
  11. T& operator*() { return *mPtr; }
  12. };
  13.  
  14. class ReallyLongClassName {
  15. public:
  16. ReallyLongClassName() {
  17. cout << "constructing ReallyLongClassName" << endl;
  18. }
  19. ~ReallyLongClassName() {
  20. cout << "destroying ReallyLongClassName" << endl;
  21. }
  22. int foo() {
  23. cout << "calling ReallyLongClassName::foo" << endl;
  24. return 42;
  25. }
  26. };
  27.  
  28.  
  29. int main()
  30. {
  31. New<ReallyLongClassName> rlcn;
  32. cout << rlcn->foo() << endl;
  33. delete rlcn;
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment