Skip to content

Instantly share code, notes, and snippets.

@benjamn
Created May 4, 2010 01:05
Show Gist options
  • Save benjamn/388817 to your computer and use it in GitHub Desktop.
Save benjamn/388817 to your computer and use it in GitHub Desktop.
#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;
}
constructing ReallyLongClassName
calling ReallyLongClassName::foo
42
destroying ReallyLongClassName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment