I can understand how it work if they are inlined. But if they are not, how does it work? does all object files get their own copy of for example the function template anyway
Templates are a complete language unto themselves. They are Turing complete, but the "program" runs at compile time. They are code factories that replace the object type at compile time and assemble classes, functions, etc. at compile time. So you can think of it as a type safe, C++ compatible massive preprocessing language. The resulting output of the execution is pure C++ code that can then be treated by the compiler the same as it does everything else.
Compilers generally ignore inline as very few programmers can really know when it's best and those who do have not left assembly.