diff options
Diffstat (limited to 'shared/com_ptr.h')
-rw-r--r-- | shared/com_ptr.h | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/shared/com_ptr.h b/shared/com_ptr.h index 1ce7eae6..52a072fa 100644 --- a/shared/com_ptr.h +++ b/shared/com_ptr.h @@ -12,7 +12,7 @@ namespace util { -/* +/* ComPtr: RAII class handling COM objects Example: @@ -39,13 +39,20 @@ public: ~ComPtr(); T** init(); //get pointer for use with ::CoCreateInstance() T* get() const; - T* release(); + T* release(); //throw() void swap(ComPtr& rhs); //throw() T* operator->() const; - operator bool() const; private: T* ptr; + + struct ConversionToBool + { + int dummy; + }; + +public: + operator int ConversionToBool::*() const; //use member pointer as implicit conversion to bool (C++ Templates - Vandevoorde/Josuttis; chapter 20) }; @@ -162,12 +169,22 @@ T* ComPtr<T>::operator->() const } +/* template <class T> inline ComPtr<T>::operator bool() const { return ptr != NULL; } +*/ + + +template <class T> +inline +ComPtr<T>::operator int ComPtr<T>::ConversionToBool::*() const +{ + return ptr != NULL ? &ConversionToBool::dummy : NULL; +} template <class S, class T> |