Fix compiler warnings about uninitialized variables
Remove DynamicPointerCast static function that was mistakenly put into the class.
Fix code to reduce casting in the template function. We still need a specialized
version of the function for bool value as we get warnings under MSVC.