Not sure what ELF and C type system has to do with this. C type information can be stored in ELF (as well as many other things). This is how a debugger can know the types.
It is simply a language design flaw of C++ that class implementation (not just templates) ended up in the headers.