Compatibility with GCC compiler: add .template in the new code for dynamic casting. (it compiled ok on MSVC compiler, not on GCC)