<p>I've been writing C and C++ code for almost twenty years, but there's one aspect of these languages that I've never really understood. I've obviously used regular casts i.e.</p>

<pre><code>MyClass *m = (MyClass *)ptr;
</code></pre>

<p>all over the place, but there seem to be two other types of casts, and I don't know the difference. What's the difference between the following lines of code?</p>

<pre><code>MyClass *m = (MyClass *)ptr;
MyClass *m = static_cast&lt;MyClass *&gt;(ptr);
MyClass *m = dynamic_cast&lt;MyClass *&gt;(ptr);
</code></pre>

```
dynamic_cast
```
has runtime type checking and only works with references and pointers, whereas
```
static_cast
```
does not offer runtime type checking. For complete information, see the MSDN article
static_cast Operator
.