C++ 函数模板的特化(Function Template Specialization)
2015-09-23 11:46
579 查看
C++ 函数模板的特化(Function Template Specialization)
flyfish 2015-9-23
某些情况下,通用模板定义对于某个类型可能是完全错误的,通用模板定义也许不能编译或者做错误的事情。
In some case ,the general template definition is simply wrong for a type:The general definition might not compile or might do the wrong thing。
非常好的例子
flyfish 2015-9-23
某些情况下,通用模板定义对于某个类型可能是完全错误的,通用模板定义也许不能编译或者做错误的事情。
In some case ,the general template definition is simply wrong for a type:The general definition might not compile or might do the wrong thing。
非常好的例子
//first version can compare any two types template <typename T> int compare(const T &v1,const T &v2) { if(v1 < v2)return -1; if(v2 < v1)return 1; return 0; } //special version of compare to handle C-style character strings template<> int compare<const char *>(const char *const &v1,const char *const &v2) { return strcmp(v1,v2); }
相关文章推荐
- SHA-256算法 C语言实现
- MD5算法 C语言实现
- 相似图片搜索原理二(phash—c++实现)
- 相似图片搜索原理一(ahash—c++实现)
- 黑马程序员----C语言学习笔记之循环结构介绍和用法举例
- 相似图片搜索原理三(颜色直方图—c++实现)
- c语言学习笔记(4)struct和union:柔性数组存储斐波那契数列以及union判断系统大小端
- 【读书笔记:C++ primer plus 第六版 中文版】第16章 string类和标准模板库
- iOS开发之SQLite--C语言接口规范(五)——iOS开发使用SQLite实例
- 黑马程序员---C语言学习笔记之语言模块化编程概念
- C++内存分配方式详解——堆、栈、自由存储区、全局/静态存储区和常量存储区
- Item 34:区分接口继承和实现继承 Effective C++笔记
- 探讨C语言中关键字volatile的含义_C
- C++设计模式——组合模式
- C语言深度学习——入门篇
- C语言实验——某年某月的天数
- FLT_MAX 和 FLT_MIN的定义
- 一种简单的c++文件操作方式
- 九九乘法表的C语言实现
- C++获取系统时间