inline int add(int a,int b){ return a + b ;}int add(int a,int b,int c,int d = 0){ return add(add(add(a,b),c),d);}
这里应用了内联,缺省,还有函数重载。
int * p = new int[4];int k = atoi(argv[1]);switch(k){case 1://代表加法if(argc == 4){p[0] = atoi(argv[2]);p[1] = atoi(argv[3]);int y = add(p[0],p[1]);cout << y << endl;//break;}else if(argc == 5){p[0] = atoi(argv[2]);p[1] = atoi(argv[3]);p[2] = atoi(argv[4]);int y = add(p[0],p[1],p[2]);cout << y << endl;}else if(argc == 6){p[0] = atoi(argv[2]);p[1] = atoi(argv[3]);p[2] = atoi(argv[4]);p[3] = atoi(argv[5]);int y = add(p[0],p[1],p[2],p[3]);cout << y << endl;}break;
这里应用new.
使用C加加实现计算器功能。可以实现加减乘除。需要用到内联。函数重载。new运算符。缺省参数