码迷,mamicode.com
首页 > 编程语言 > 详细

C++模板重载

时间:2018-08-08 00:27:38      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:++   code   函数   swa   参数   template   就是   执行   temp   

C++模板重载能够执行同一个任务,不通数据类型的函数,也就是说,当我们定义一个模板,当模板函数有int类型,它就执行int类型的相关任务,当参数为char数据类型时,就执行char类型的相关任务。 比如交换两个数的位置,则应该在main函数之前定义好,main函数之前定义为: template <class sw> void Swap( sw &a, sw &b); template <class sw> void Swap( sw *a, sw *b); 在main函数之后则是实现: template <class sw> void Swap(sw &a, sw &b) { 具体实现; } template <class sw > void Swap(sw a[], sw b[], int n ) { 具体实现; }

C++模板重载

标签:++   code   函数   swa   参数   template   就是   执行   temp   

原文地址:http://blog.51cto.com/10018586/2155975

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!