Sign in to follow this  
Dragon_Strike

smart pointers for dx objects?

Recommended Posts

would doing something like this for Directx objects be a good idea? template <class T> class auto_dx { public: T* ptr; explicit auto_dx(T* p = 0) : ptr(p) {} ~auto_dx() {SAFE_RELEASE(ptr);} T& operator*() {return *ptr;} T* operator->() {return ptr;} };

Share this post


Link to post
Share on other sites
would doing something like this for Directx objects be a good idea?
No, this functionally is already there see smart com pointers.
http://msdn2.microsoft.com/en-us/library/ezzw7k98(vs.80).aspx

Share this post


Link to post
Share on other sites
Using boost::shared_ptr seems kind of silly, since then there will be multiple reference counts for the same object. You might as well use boost::intrusive_ptr, if you go the boost route. Of course, Microsoft provides a number of smart pointers for use with COM, such as ATL's CComPtr and CComQIPtr, which can be used in any environment that supports ATL or _com_ptr_t, which is specific to MSVC.

Share this post


Link to post
Share on other sites
_com_ptr_ sounds great... but it needs the header <atlbase.h...but i cant compile it since i always get the error... "Need to include strsafe.h after tchar.h"
... ive tried putting tchar first of all my includes but i still get the same error...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this