Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cout;
- using std::endl;
- template <typename T> class New {
- T* mPtr;
- public:
- New() : mPtr(new T()) {}
- operator T*() { return mPtr; }
- T* operator->() { return mPtr; }
- T& operator*() { return *mPtr; }
- };
- class ReallyLongClassName {
- public:
- ReallyLongClassName() {
- cout << "constructing ReallyLongClassName" << endl;
- }
- ~ReallyLongClassName() {
- cout << "destroying ReallyLongClassName" << endl;
- }
- int foo() {
- cout << "calling ReallyLongClassName::foo" << endl;
- return 42;
- }
- };
- int main()
- {
- New<ReallyLongClassName> rlcn;
- cout << rlcn->foo() << endl;
- delete rlcn;
- return 0;
- }
Add Comment
Please, Sign In to add comment