千巷猫影
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273// baiduzhidao02.cpp : Defines the entry point for the console application.// #include "stdafx.h"#include <stdio.h> class MyClass{public: MyClass(){}; ~MyClass(){}; void Print(int a) { printf("int类型:%d\n", a); }; void Print(float a) { printf("float类型:%f\n", a); } void Print(double a) { printf("double类型:%f\n", a); } void Print(int a[]) { int size = sizeof(a) - 1; for (int i = 0; i < size; i++) { Print(a[i]); } } void Print(float a[]) { int size = sizeof(a) - 1; for (int i = 0; i < size; i++) { Print(a[i]); } } void Print(double a[]) { int size = sizeof(a) - 1; for (int i = 0; i < size; i++) { Print(a[i]); } }}; int main(int argc, char* argv[]){ int a = 520; float b = 521.0; double c = 522.0; int array1[] = { 1, 2, 3 }; float array2[] = { 4.0, 5.0, 6.0 }; double array3[] = { 7.0, 8.0, 9.0 }; MyClass myclass; //输出a,b,c myclass.Print(a); myclass.Print(b); myclass.Print(c); //输出array1,array2,array3 myclass.Print(array1); myclass.Print(array2); myclass.Print(array3); return 0;}
温温酱
12345678910111213141516171819202122232425262728293031323334353637383940414243class MyClass{public: Print(int x){ printf("%d\n",x); } Print(float x){ printf("%f\n",x); } Print(double x){ printf("%lf\n",x); } Print(int* x,int n) { for(int i=0;i<n;i++) { printf("%d\n",*x);x++; } } Print(float* x,int n) { for(int i=0;i<n;i++) { printf("%f\n",*x);x++; } } Print(double* x,int n) { for(int i=0;i<n;i++) { printf("%lf\n",*x);x++; } }}; main(){ int a=3;float b=3.14;double c=1.414; int e[]={1,2,3,4}; float f[]={1.23,2.34,3.45}; double g[]={9.87,8.76,7.65,6.54}; MyClass my; my.Print(a); my.Print(b); my.Print(c); my.Print(e,sizeof(e)/sizeof(int)); my.Print(f,sizeof(f)/sizeof(float)); my.Print(g,sizeof(g)/sizeof(double));}