65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
void test(void* value,int TYPE_VALUE)
{//TYPE_VALUE: 0-int ; 1-float;2-double;3-char*
switch(TYPE_VALUE)
{
case 0:
{ int* tmp = (int*)value;
cout<<*tmp<<endl;
break;
}
case 1:
{ float* tmp = (float*)value;
cout<<*tmp<<endl;
break;
}
case 2:
{ double* tmp = (double*)value;
cout<<*tmp<<endl;
break;
}
case 3:
cout<<(char*)value<<endl;
default:
break;
}
}
int main(void)
{
int a = 100000;
float b = 2222;
double c = 3333333.333;
char d[] = "test";
test(&a,0);
test(&b,1);
test(&c,2);
test(d,3);
return 0;
}