2016/6/3 1005. Template Specification
来源:互联网 发布:淘宝客设置流程 卖家 编辑:程序博客网 时间:2024/06/03 16:36
这道题要用的是模板的具体化(废话看题目就知道啦)。(嗯具体化是template< >,实例是template Type Func_Name < >)只要具体化char* 和T* 就可以了。
#pragma warning (disable:4996)#include <iostream>#include <cstring>#include <string>using namespace std;template <typename T>bool cmp(T a, T b){return a == b;}template <typename T>bool cmp(T* a, T* b){return *a == *b;}template <> bool cmp(char* a, char* b){return !strcmp(a, b);}int main(){int aInt = 1, bInt = 1;double aDouble = 3.0, bDouble = 3.0;char aChars[5] = "haha", bChars[5];string aStr = "haha", bStr = "aha";int* aIntPtr = &aInt, *bIntPtr = &bInt;cout << boolalpha << cmp(aInt, bInt) << endl;cout << cmp(aDouble, bDouble) << endl;strcpy(bChars, aChars);cout << cmp(aChars, bChars) << endl;cout << cmp(aStr, bStr) << endl;cout << cmp(aIntPtr, bIntPtr) << endl;}
0 0
- 2016/6/3 1005. Template Specification
- Lecture 6: Specification
- 3pg/mp4 specification
- 3GPP Specification Numbering
- 3 Spring JPA Specification 查询
- Tapestry的template和specification定义在不同文件夹的方法
- Tapestry的template和specification定义在不同文件夹的方法
- Tapestry的template和specification定义在不同文件夹的方法
- OpenCL 1.0 Specification阅读笔记(6)
- JSR 3: Java Management Extensions (JMX) Specification
- OpenCL 1.0 Specification阅读笔记(3)
- JVMS Specification(3)-The class File Format
- Template Usage Scenario 3
- umbraco学习3:Template
- string模块3 - template
- template模板3
- template
- Template
- TCP连接状态解析和过程分析
- 利用tikz画图时调整node内部文字行距的方法
- C++标准转换运算符static_cast
- android媒体在二级设备上呈现和播放
- 架构
- 2016/6/3 1005. Template Specification
- BitMap的recycle问题
- 截包与重放是个技术活
- 附源码:PHP实现查询汉字笔画、笔画排序
- JAVA使用增强for循环和迭代器遍历Map集合
- 阿里云主机服务器端配置
- 确定网页适配及流量压缩的业务流量的方法、系统和设备
- Andorid通用流行框架
- (转)iPhone实战:动态改变UITableView中的Cell高度