功能模板专业化语法 [英] Function Template Specialization Syntax

查看:171
本文介绍了功能模板专业化语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定此函数模板:

template<typename A> void func (A param) {...}

这个成语(A)

template<> void func<> (int param) {...}


$ b

Or this one (B)

template<> void func<int> (int param) {..}

A和B之间有什么区别吗?如果两者都相同,那么首选语法和原因是什么?

Is there any difference between A and B? If both are the same, what's the preferred syntax and why?

推荐答案

A。) template< ; void func<> (int param){...}

B)模板< void func< int> (int param){..}

A和B之间有什么区别?

技术上B有明确指定的模板参数,而A有它的参数减少,但对用户来说,它只是你如何呈现你的函数。

Technically B has the template argument explicitly specified while A has it's argument reduced, but to the user it's merely how you present your function.

如果两者都相同,则首选语法和原因是什么?

由于定义二者会导致多重定义错误他们是相同的功能),它是真的由个人喜好如何呈现的功能。

Since defining both would result in a multiple definition error (i.e. they're the same function), it's really up to personal preference as to how you present the function.

我个人偏向于B,因为它完全定义并清楚地说明了功能的意图,但同样是我的个人偏好

I'm personally partial to B since it fully defines and clearly states intention of function, but again that's my personal preference

希望可以帮助

这篇关于功能模板专业化语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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