先看一下C++中的默认参数实现
void Test(int x = 1, int y = 2, int z = 3){cout << x << ", " << y << ", " << z << endl ;}int main(void){Test() ;Test(10) ;Test(10, 20) ;Test(10, 20, 30) ;system("pause") ;
return 0 ;
}如何在C中实现这种效果呢?目前只找到一种方法,宏定义,遗憾的是不能使用同一个函数名了
#define Test0() Test(1, 2, 3)#define Test1(x) Test(x, 2, 3)#define Test2(x, y) Test(x, y, 3)#define Test3(x, y, z) Test(x, y, z)void Test(int x, int y, int z){cout << x << ", " << y << ", " << z << endl ;}
原文链接: https://www.cnblogs.com/graphics/archive/2010/07/14/1777010.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/12714
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!