Duplicate c++ template instantiations

前端 未结 4 765
迷失自我
迷失自我 2020-12-17 16:16

Is it possible for the compiler to duplicate instantiations of a same template across several translation units?

For instance, if you have a.cpp which use a st

4条回答
  •  隐瞒了意图╮
    2020-12-17 16:57

    I think that the compiler uses the same mechanism as with member functions of ordinary classes. It can make them inline and I presume that it leaves information around that the linker uses to sort it out for the final binary.

    The only difference is that the compiler 'writes' the definitions - that is the 'instantiation' of a template - but it manages to make exactly the same instantiation whilst compiling either of a.cpp or b.cpp

提交回复
热议问题