Are methods of templated classes implied inline linkage?

前端 未结 1 1044
不知归路
不知归路 2021-01-05 23:33

Are methods of templated classes implied inline linkage (not talking about the inline optimization), or is it just templated methods which are?

         


        
相关标签:
1条回答
  • 2021-01-06 00:03

    Template functions and member functions of template classes are implicitly inline if they are implicitly instantiated, but beware template specializations are not.

    template <typename T>
    struct test {
        void f();
    }
    template <typename T>
    void test<T>::f() {}           // inline
    
    template <>
    void test<int>::f() {}           // not inline
    

    By lack of a better quote:

    A non-exported template must be defined in every translation unit in which it is implicitly instantiated (14.7.1), unless the corresponding specialization is explicitly instantiated (14.7.2) in some translation unit; no diagnostic is required

    0 讨论(0)
提交回复
热议问题