Function template specialization

后端 未结 3 874
北恋
北恋 2020-12-16 16:20

While reading this, I\'m confused by the following examples:

// Example 2: Explicit specialization 
// 
template // (a) a base template 
void          


        
3条回答
  •  [愿得一人]
    2020-12-16 16:38

    It's the order but it's not only the order. For the first code, both templates was defined before. But the second was taken.

    This is because the two templates are compared and it is found that (T) matches any type that (T*) matches, but that (T*) does not match all types that (T) matches. Thus, the second template is more specialized. Whenever you put an explicit specialization and those two templates match, the templates are compared and the more specialized one is associated by the explicit specialization. This comparison is called "partial ordering".

提交回复
热议问题