C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c – Template Explicit Specialization和普通函数有什么区别?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
template <class T>
void max (T &a,T &b)
{}//generic template   #1

template<> void max(char &c,char &d)
{} //template specializtion    #2

void max (char &c,char &d)
{}//ordinary function      #3

1,2和3之间有什么区别?

解决方法

>是一个模板函数
>是以前的模板功能的总体专业化(不会超载!)
>是功能的重载

这是C++ Coding Standards: 101 Rules,Guidelines,and Best Practices摘录:

本书建议您通过根据类模板实现功能模板来添加间接级别:

#include <algorithm>

template<typ@R_616_8371@ T>
struct max_implementation
{
  T& operator() (T& a,T& b)
  {
    return std::max(a,b);
  }
};

template<typ@R_616_8371@ T>
T& max(T& a,T& b)
{
  return max_implementation<T>()(a,b);
}

也可以看看:

> Why Not Specialize Function Templates?
> Template Specialization and Overloading

大佬总结

以上是大佬教程为你收集整理的c – Template Explicit Specialization和普通函数有什么区别?全部内容,希望文章能够帮你解决c – Template Explicit Specialization和普通函数有什么区别?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。