smart pointers for dx objects?
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;}
};
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
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement