问答题
#include < iostream.h >
class Test
{ int x, y;
public:
void fun(int i, int j)
{x=i; y=j;}
void show()
{ cout << "x = " << x;
if(y)
cout << ", y = " << y << endl;
cout << endl; }
};
void main()
{ Test a;
a.fun(1);
a.show();
a.fun(2,4);
a.show();
}
【参考答案】
int i, int j调用fun函数时,既有一个参数,也有两个参数,且没有重载,所以fun函数的参数需要带默认值。所以......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)