user47480: 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.   

user23841: For doing:
shared_ptr<Base_class> b_ptr;
shared_ptr<Child_class> ptr(b_ptr);

you have to use another constructor. If you take a look on this Example of shared_ptr implementation, you can see:
template<class U> shared_ptr(const shared_ptr<U>& s) ...

That's exactly the constructor, that takes shared_ptr of different type .
And similarly for assigment operator.

47480: <p>I am using custom shared_ptr class for some program on Arduino, and I need to do something like this:</p>

<pre><code>shared_ptr&lt;Base_class&gt; b_ptr;
shared_ptr&lt;Child_class&gt; ptr((shared_ptr&lt;Child_class&gt;) b_ptr);
</code></pre>

<p>In my shared_ptr class I have three constructors:</p>

<pre><code>shared_ptr() : pData(0), reference(0){...}
shared_ptr(T* pValue) : pData(pValue), reference(0){...}
shared_ptr(const shared_ptr&lt;T&gt;&amp; sp) : pData(sp.pData), reference(sp.reference){...}
</code></pre>

<p>and some other stuff...
For casting I tried to write the following:</p>

<pre><code>    template&lt; typename T2 &gt;
operator T2 * () const
{
   return (T2 *)pData;
}
</code></pre>

<p>and:</p>

<pre><code>    template&lt; typename T2 &gt;
operator shared_ptr&lt;T2&gt; () const
{
    shared_ptr&lt;T2&gt; temp((T2 *)pData);
    return temp;
}
</code></pre>

<p>but can't get it to work.   </p>
 23841: <p>For doing:</p>

<pre><code>shared_ptr&lt;Base_class&gt; b_ptr;
shared_ptr&lt;Child_class&gt; ptr(b_ptr);
</code></pre>

<p>you have to use another constructor. If you take a look on this <a href="https://stackoverflow.com/a/9201435/5271927">Example of shared_ptr implementation</a>, you can see:</p>

<pre><code>template&lt;class U&gt; shared_ptr(const shared_ptr&lt;U&gt;&amp; s) ...
</code></pre>

<p>That's exactly the constructor, that takes shared_ptr of different type .</p>

<p>And similarly for assigment operator.</p>
