I'm not sure why you were told that polymorphism isn't type-safe. It's one of the basic driving features of the C++ language. You would never "try to use a sound file as a text file" if you design your library correctly.
It sounds like that program is just badly coded, then.Ogre3d does this and it is one of the main flaws of their engine. People try to program for ogre and end up breaking things because they accidentally grab a sound file and try to output it as a 3d model on the screen.
It can't be done this way because the compiler doesn't know what "T" is. You are asking "T" to stand for some type that can only be determined at runtime. A template just can't do that.It's really not a big big problem, but I'd rather do it this way, the type safe way.