“template<>” vs “template” without brackets - what's the difference?

后端 未结 2 1624
情话喂你
情话喂你 2020-12-02 15:16

Suppose I\'ve declared:

template  void foo(T& t);

Now, what is the difference between

template <&         


        
相关标签:
2条回答
  • 2020-12-02 15:46

    template <> void foo<int>(int& t); declares a specialization of the template, with potentially different body.

    template void foo<int>(int& t); causes an explicit instantiation of the template, but doesn't introduce a specialization. It just forces the instantiation of the template for a specific type.

    0 讨论(0)
  • 2020-12-02 15:47

    With class/struct,

    template <typename T> struct foo {};
    

    Following is a specialization:

    template <> struct foo<int>{};
    

    Following is an explicit instantiation:

    template struct foo<int>;
    
    0 讨论(0)
提交回复
热议问题