65,210
社区成员
发帖
与我相关
我的任务
分享// csdn_09_11_11.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
struct byte;
template<typename T>
struct Mytype{
static void fun(void* img, int size)
{
cout<<"没有这种类型"<<endl;
}
};
template<>
struct Mytype<byte>
{
static void fun(void* img, int size)
{
cout<<"byte类型,在这儿实现"<<endl;
}
};
template<>
struct Mytype<float>
{
static void fun(void* img, int size)
{
cout<<"float类型,在这儿实现"<<endl;
}
};
template<typename T>
void fun(void* img,int size)
{
Mytype<T>::fun(img,size);
}
int _tmain(int argc, _TCHAR* argv[])
{
fun<char>(0,0);
fun<float>(0,0);
fun<byte>(0,0);
return 0;
}
template <typename T>
void process(T& a)
{
a = a+ T(1);
}
void process(string & s)
{
s.append(_T(' '));
}
template <typename T>
void fun(T* img,int count)
{
int i;
for(i=0; i<count; i++) {
process(img[i]);
};
}