After the last problem, I encountered another.

Continuing on the shared pointer, I cannot assign the right-hand side m_ptr to the left-hand side because it's a templated-type pointer (see code).

So, I wrapped the pointer in a struct, yet I still cannot seem to get it right. I was hoping anyone with some good eyes or some free time could help me with it.

Minimal code snippet:

Test code:Code:#ifndef MAD_SHARED_PTR_175451_H #define MAD_SHARED_PTR_175451_H #ifndef NULL #define NULL 0 #endif const int nullptr = NULL; #include <assert.h> class nullptr_t {}; template<int Bits> class ptr_thread_dangerous { }; class Derived; template<typename T, template<int> class thread_safety = ptr_thread_dangerous, int Bits = 32> class mad_shared_ptr { protected: template<typename T, int Bits> struct sptr { }; template<typename T, int Bits> class sptr_wrapper { public: sptr_wrapper(sptr<T, Bits>* p): m_p(p) {} /*template<typename OtherT> */sptr_wrapper& operator = (const sptr_wrapper<Derived, 32>& rhs) { m_p->p = rhs.p; m_p->RefCount = rhs.RefCount; m_p->pDeleter = rhs.pDeleter; } protected: sptr<T, Bits>* m_p; }; typedef sptr<T, Bits> ptr_t; public: mad_shared_ptr(): m_ptr(nullptr) { } template<typename Other> mad_shared_ptr(Other* p): m_ptr(nullptr) { *this = p; } template<typename Other> mad_shared_ptr(const mad_shared_ptr<Other>& rhs): m_ptr(nullptr) { *this = rhs; } template<typename Other> mad_shared_ptr& operator = (const mad_shared_ptr<Other>& rhs) { m_ptr = rhs.m_ptr; return *this; } protected: sptr_wrapper<T, Bits> m_ptr; template<typename Other, template<int> class thread_safety, int Bits> friend class mad_shared_ptr; }; #endif // MAD_SHARED_PTR_175451_H

And the error would be:Code:#include <... mad_shared_ptr.h> class Base {}; class Derived: public Base {}; int main() { mad_shared_ptr<Base> p; mad_shared_ptr<Derived> p2 = new Derived(); p = p2; }

1>error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const mad_shared_ptr<T>::sptr_wrapper<T,Bits>' (or there is no acceptable conversion)

1> with

1> [

1> T=Derived,

1> Bits=32

1> ]

1> could be 'mad_shared_ptr<T>::sptr_wrapper<T,Bits> &mad_shared_ptr<T>::sptr_wrapper<T,Bits>::opera tor =(const mad_shared_ptr<T>::sptr_wrapper<Derived,32> &)'

1> with

1> [

1> T=Base,

1> Bits=32

1> ]

1> or 'mad_shared_ptr<T>::sptr_wrapper<T,Bits> &mad_shared_ptr<T>::sptr_wrapper<T,Bits>::opera tor =(const mad_shared_ptr<T>::sptr_wrapper<T,Bits> &)'

1> with

1> [

1> T=Base,

1> Bits=32

1> ]

1> while trying to match the argument list '(mad_shared_ptr<T>::sptr_wrapper<T,Bits>, const mad_shared_ptr<T>::sptr_wrapper<T,Bits>)'

1> with

1> [

1> T=Base,

1> Bits=32

1> ]

1> and

1> [

1> T=Derived,

1> Bits=32

1> ]

Basically it's saying it can't find an assignment operator that takes sptr_wrapper<Base, 32> (which the lhs should be, and is, according to the error) and a sptr_wrapper<Derived, 32> (the very exact operator I tried adding).

If anyone spots a problem, I'd be grateful for any help.