How do i rewrite this typecast so nonsense is a compile time error?
<p><a href="http://www.ideone.com/bPzBI" rel="nofollow">This code compiles</a>. Its obviously wrong because B can never be a WTF. Is there a way i can write the typecast so this is a compile time error?</p>

<pre><code>class B{ public: virtual void abc(){} };
class D1 : public B{};
class WTF{ };

template&lt;class T, class TT&gt;
T DoSomething(TT o){
        return dynamic_cast&lt;T&gt;(o);
}
B*Factory() { return new D1; }
int main(){
        DoSomething&lt;D1*, B*&gt;(Factory());
        DoSomething&lt;WTF*, B*&gt;(Factory());
}
</code></pre>
