Fixed thread statics

Thread statics were not compiling due to not being able to get a const reference to the memory instance. Fixed by adding a new function to get a const pointer. Required for thread static tests to pass in #728.
To fix the compile error you should have just changed this line to:
```C++
const type &_const_cast() const { return *static_cast<const type *>( getMemInstPtr() ); } \
```
And avoided all the other unnecessary changes. See [When to use reinterpret_cast?](http://stackoverflow.com/a/573345/139041) stackoverflow answer for details.