大佬教程收集整理的这篇文章主要介绍了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,请注明来意。