|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- # include <iostream>
- using namespace std;
- class Point
- {
- public:
- int x ;
- int y ;
- Point ()
- {
- x = 0;
- y = 0;
- }
- Point (int a, int b)
- {
- x = a;
- y = b;
- }
- ~Point()
- {
- }
- void Output()
- {
- cout << x <<endl << y << endl;
- }
- void Output(int x, int x)
- {
- x = x;
- y = x;
- }
- };
- int main (void)
- {
- Point P(3, 3);
- P.Output(5, 5);
- P.Output();
- return 0;
- }
复制代码 大虾们,给俺看看这个是为什么?以上是第一个代码输出的结果是3,3
我修改了
- void Output(int x, int x)
- {
- x = x;
- y = x;
- }
复制代码 以后的代码- # include <iostream>
- using namespace std;
- class Point
- {
- public:
- int x ;
- int y ;
- Point ()
- {
- x = 0;
- y = 0;
- }
- Point (int a, int b)
- {
- x = a;
- y = b;
- }
- ~Point()
- {
- }
- void Output()
- {
- cout << x <<endl << y << endl;
- }
- void Output(int a, int b)
- {
- x =a;
- y = b;
- }
- };
- int main (void)
- {
- Point P(3, 3);
- P.Output(5, 5);
- P.Output();
- return 0;
- }
复制代码 输出结果变成了5,5我只是改动了
void Output(int a, int b)
{
x =a;
y = b;
}中形参的名称而已!请问为什么会有如此大的不同!
|
|