I want to write an auto_ptr implementation for Core Foundation objects, but I'm having a little problem with making a converting constructor.
I thought this would do it, but I get errors when I use it like this:Code:template <typename T> class CF_auto_ptr { public: CF_auto_ptr(T p = 0); ~CF_auto_ptr(); CF_auto_ptr<T>(CF_auto_ptr<T>& rhs); CF_auto_ptr<T>& operator=(CF_auto_ptr<T> rhs); T get() const; void release(); void reset(T p); private: T p; }; template <typename T> CF_auto_ptr<T>::CF_auto_ptr(T p) : p(p) {} template <typename T> CF_auto_ptr<T>::~CF_auto_ptr() { if (p) { CFRelease(p); } } template <typename T> CF_auto_ptr<T>::CF_auto_ptr(CF_auto_ptr<T>& rhs) { p = rhs.get(); rhs.release(); } template <typename T> CF_auto_ptr<T>& CF_auto_ptr<T>::operator=(CF_auto_ptr<T> rhs) { p = rhs.get(); rhs.release(); return *this; }
Code:CF_auto_ptr<CFBundleRef> main_bundle = CFBundleGetMainBundle();Code:error: no matching function for call to 'CF_auto_ptr<__CFBundle*>::CF_auto_ptr(CF_auto_ptr<__CFBundle*>)'Code:candidates are: CF_auto_ptr<T>::CF_auto_ptr(CF_auto_ptr<T>&) [with T = __CFBundle*]



LinkBack URL
About LinkBacks


