C++ trait example
来源:互联网 发布:php开发api接口教程 编辑:程序博客网 时间:2024/06/06 03:51
an example modified
#include<iostream>
using namespace std;
template<typename T>
class AccumulationTraits;
template<>
class AccumulationTraits<char>{
public:
typedef int AccT;
static AccT zero(){
return 0;
}
};
template<>
class AccumulationTraits<short>{
public:
typedef int AccT;
static AccT zero(){
return 0;
}
};
template<>
class AccumulationTraits<int>{
public:
typedef long AccT;
static AccT zero(){
return 0;
}
};
template<typename T,typename AT = AccumulationTraits<T> >
class Accum{
public:
static typename AT::AccT accum(T const * beg,T const * end){
typename AT::AccT total = AT::zero();
while(beg !=end){
total += *beg;
++beg;
cout<<" abcd"<<endl;
}
return total;
}
};
int main()
{
const int num[5] = {1,2,3,4,5};
//accum(&num[0],&num[4]);
typedef Accum <char> test;
test testabc;
const char testchar[8] = "abcdefg";
// testabc(&testchar[0],&testchar[7]);
char testa = 'a';
char testb = 'b';
const char * ptesta = &testa;
const char * ptestb = &testb;
//testabcthis->init(__sb)
testabc.accum(&testchar[0],&testchar[7]);
Accum<char> test2;
//test2 test3; //
//test3.Accum(&testchar[0],&testchar[7]); //error,should be an typedef then object value
return 0;
}
- C++ trait example
- Trait
- trait
- Trait
- trait
- trait
- trait
- [C++] CBT Hook Example
- HttpListener in C#:example
- 编译output-example.c
- Output example.c
- [Home] JSON-C Example
- FFMPEG Output example.c
- C#_delegate - example
- C callback function example
- 编译output-example.c
- c api example
- alsa record example.c
- 多屏融合下的流媒体技术
- 栈和队列
- gson在android中的使用例子
- 浮点数(float)和双精度(double)截断问题
- 用异或实现两个数的交换&x&(x-1)表达式作用&计算前1500个丑数
- C++ trait example
- CMMI3级介绍
- 探索微博营销的价值点
- Oracle笔记(八) 复杂查询及总结
- ubuntu10.4安装交叉编译器arm-none-linux-gnueabi-gcc
- java中如何获取项目各个目录下的文件
- 关于bootstrap模版Bootstrapper的问题
- 百度关键词排名提高方法
- mp3 音频 音乐 tag ID3 ID3V1 ID3V2 标签 读取信息 获得图片 jpeg bmp 图片转换