Partial template specialization ambiguity

前端 未结 1 2194
清歌不尽
清歌不尽 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 and X:

    • X matches the first but not the second.
    • X 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)
提交回复
热议问题