I am using custom shared_ptr class for some program on Arduino, and I need to do something like this:
shared_ptr<Base_class> b_ptr;
shared_ptr<Child_class> ptr((shared_ptr<Child_class>) b_ptr);
In my shared_ptr class I have three constructors:
shared_ptr() : pData(0), reference(0){...}
shared_ptr(T* pValue) : pData(pValue), reference(0){...}
shared_ptr(const shared_ptr<T>& sp) : pData(sp.pData), reference(sp.reference){...}
and some other stuff... For casting I tried to write the following:
template< typename T2 >
operator T2 * () const
{
return (T2 *)pData;
}
and:
template< typename T2 >
operator shared_ptr<T2> () const
{
shared_ptr<T2> temp((T2 *)pData);
return temp;
}
but can't get it to work.