![]() |
#2
peach54602014-02-27 09:40
|

#include"iostream.h"
class point
{
private:
int x,y;
public :
point (int xx=0,int yy=0)
{
x=xx;
y=yy;
}
int getx()
{
return x;
}
int gety()
{return y;}
friend point operator++(point &P);
};
point operator++(point &p)
{
++p.x ;
++p.y ;return p;
}
void main()
{
point ob(3,4);
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
++ob;
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
operator++(ob);
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
}
point operator++(point &p) 里面的&的具体作用是什么 怎么取址的 如果把&去掉 为什么不能实现自增啊 麻烦大家把原理讲的详细点 class point
{
private:
int x,y;
public :
point (int xx=0,int yy=0)
{
x=xx;
y=yy;
}
int getx()
{
return x;
}
int gety()
{return y;}
friend point operator++(point &P);
};
point operator++(point &p)
{
++p.x ;
++p.y ;return p;
}
void main()
{
point ob(3,4);
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
++ob;
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
operator++(ob);
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
}