0
#include<iostream>
using namespace std;
class a
{
private:
int x;
int y;
public:
int getx()
{
return x;
}
int gety()
{
return y;
}
a()
{
x = 100;
y = 100;
}
void xmin()
{
x--;
}
void ab(a x)
{
x.xmin(); x.xmin(); x.xmin(); x.xmin();
}
};
void main()
{
a xx;
a yy;
cout << "xx" << endl;
cout << "x : " << xx.getx() << "y : " << xx.gety()<<endl;
cout << "yy" << endl;
cout << "x : " << yy.getx() << "y : " << yy.gety()<<endl;
xx.ab(yy);
cout << "xx" << endl;
cout << "x : " << xx.getx() << "y : " << xx.gety() << endl;
cout << "yy" << endl;
cout << "x : " << yy.getx() << "y : " << yy.gety() << endl;
}
爲什麼函數x.xmin()
在void ab(a x)
中無法正確執行? (中x
的價值並沒有改變作爲xmin()
功能由1不能調用類函數(參數類)
減少x
值這是我的代碼的簡單版本,這樣會更容易理解:)
您傳遞的值作爲PARAM不是對象它的自我,你必須通過參考'無效AB(A&X)' – rednaks
應該是'int main' –