Effective C++ .47 traits与模板特化
2024-08-28 04:29:35
#include <iostream>
#include <cstdlib>
#include <string> using namespace std; template<class T, class P>
T mul(T a, P b) {
return a * b;
} template<>
string mul<string, int>(string a, int b) {
string res;
for (int i=b; i>; i--) {
res.append(a);
}
return res;
} int main() {
cout<<mul(,)<<endl; cout<<mul(string("haha"),)<<endl;
return ;
}
traits对于基本类型可以采用特化方式为其'添加'一些属性(因为原本基本类型没有也不能在加入自定义的属性)
最新文章
- codegate-quals-2013-vuln100
- AOP和IOC的实现原理(用到的设计模式)
- Linux 下以其他用户身份运行程序—— su、sudo、runuser
- memcached for windows 修改端口和最大内存,以及常用命令
- mac上parallel与virtualbox无法共存
- 深入剖析PHP输入流 php://input (转载 http://www.nowamagic.net/academy/detail/12220520)
- WCF SOA服务应用
- Android 系统日期时间的获取
- C#学习日志 day8 -------------- async await 异步方法入门(引用博客)以及序列化和反序列化的XML及json实现
- osgi实战学习之路:3. osgi分层概念及相互合作demo
- Linux虚拟机下安装配置MySQL
- pulseaudio的交叉编译
- Excle巧取汉字打头的字串内容
- 练习:javascript分享划过简单效果
- Spark 广播变量BroadCast
- Java 基础 IO流
- 01:golang开发环境
- 大数据新手之路四:联合使用Flume和Kafka
- C# 程序设置开机启动(一)
- tag-SMASS-1