“模板”与“模板”没有括号-有什么区别? [英] "template<>" vs "template" without brackets - what's the difference?

查看:109
本文介绍了“模板”与“模板”没有括号-有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经声明:

  template< typename T>无效foo(T& t); 

现在,



<$有什么区别p $ p> 模板<> void foo< int>(int& t);

  template void foo< int>(int& t); 

显然吗?在其他情况下,无括号模板和无括号模板还有其他语义吗?






相关:
如何强制C ++模板的特定实例实例化?

解决方案

template<> void foo< int>(int& t); 声明模板的专业化,其主体可能不同。



template void foo< int>(int& t); 导致模板的显式实例化,但未引入专门化。只是强制为特定类型实例化模板。


Suppose I've declared:

template <typename T> void foo(T& t);

Now, what is the difference between

template <> void foo<int>(int& t);

and

template void foo<int>(int& t);

semantically? And do template-with-no-brackets and template-with-empty-brackets have other semantics in other contexts?


Related to: How do I force a particular instance of a C++ template to instantiate?

解决方案

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.

这篇关于“模板”与“模板”没有括号-有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆