标签:
一、
默认参数
#include <iostream> using namespace std; void fun(int i = 30, int j = 20, int k = 10); int main() { fun(); fun(100); fun(100, 200); fun(100, 200, 300); return 0; } void fun(int i, int j, int k) { cout<<i<<", "<<j<<", "<<k<<endl; }
二、
重载
#include <iostream> using namespace std; void fun(int i = 30, int j = 20, int k = 10); void fun(double i, double j); int main() { fun(1.1, 1.2); fun(1, 2); return 0; } void fun(int i, int j, int k) { cout<<i<<", "<<j<<", "<<k<<endl; } void fun(double i, double j) { cout<<i<<", "<<j<<endl; }
结果:
内联函数:
#include <iostream> using namespace std; void fun(int i = 30, int j = 20, int k = 10); inline void fun(double i, double j); int main() { fun(1.1, 1.2); fun(1, 2); return 0; } void fun(int i, int j, int k) { cout<<i<<", "<<j<<", "<<k<<endl; } void fun(double i, double j) { cout<<i<<", "<<j<<endl; }
如图:
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u012965373/article/details/46830015