Determine inheritance at compile time
<p>I have some code that behaves like this:</p>

<pre><code>class Base {};

class MyClass : public Base {};

MyClass* BaseToMyClass(Base* p)
{
  MyClass* pRes = dynamic_cast&lt;MyClass*&gt;(p);
  assert(pRes);
  return pRes;
}
</code></pre>

<p>Is there a way to add a compile time check so I can catch calls to this function where p is not an instance of MyClass?  I had a look at Alexandrescu's SUPERSUBCLASS function but I'm not sure if it can do the job.</p>

<p>Thanks!</p>
