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

和自甴很熟 提交于 2019-11-27 18:39:19
Mark B

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.

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>;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!