smart pointers for dx objects?

Started by
3 comments, last by Dragon_Strike 16 years, 3 months ago
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;} };
Advertisement
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
Or you could pass a custom destructor for the ::release to a boost::shared_ptr if that's the behavior you wanted.
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.
_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...

This topic is closed to new replies.

Advertisement