Created
May 4, 2010 01:05
-
-
Save benjamn/388817 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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