How to use explicit template instantiation to reduce compilation time?

后端 未结 2 1379
夕颜
夕颜 2021-01-04 06:48

It was suggested to use explicit template instantiation to reduce compilation time. I am wondering how to do it. For example

// a.h
template         


        
2条回答
  •  独厮守ぢ
    2021-01-04 07:25

    Declare the instantiation in the header:

    extern template class A;
    

    and define it in one source file:

    template class A;
    

    Now it will only be instantiated once, not in every translation unit, which might speed things up.

提交回复
热议问题