• Advertisement
Sign in to follow this  

smart pointers for dx objects?

This topic is 3673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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

Share this post


Link to post
Share on other sites
Or you could pass a custom destructor for the ::release to a boost::shared_ptr if that's the behavior you wanted.

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
Sign in to follow this  

  • Advertisement