C++ How do compilers handle templates

后端 未结 3 1221
孤城傲影
孤城傲影 2021-01-20 19:56

As some of you may know from my recent posts i am studying for a C++ exam which the content for the class was delivered very poorly. I am basically having to self teach ever

3条回答
  •  独厮守ぢ
    2021-01-20 20:28

    For each instance of an object of a different type that you create or in case of functions the different type of arguments that you use, the compiler simply makes an overloaded version at compile time. So if you have a template function like a sort function and use that function for int and double arrays, then the compiler have actually made two functions: one using int and the other using double. This is the simplest explanation I could give. Hope it's useful.

提交回复
热议问题