Partial template specialization ambiguity

前端 未结 1 2195
清歌不尽
清歌不尽 2021-02-19 16:36

I cant see why the statement in main is ambiguous.

template struct X
{ void f() { cout << \"Primary template\" << endl         


        
相关标签:
1条回答
  • 2021-02-19 17:07

    A template specialization is more specialized than another if every argument list that matches the first also matches the second, but not the other way around.

    When looking at X<int, T*, 10> and X<T, T*, I>:

    • X<int, float*, 10> matches the first but not the second.
    • X<float, float*, 10> matches the second but not the first.

    Therefore neither is more specialized than the other, and a template instantiation that matches both specializations won't compile.

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