C++结果555

来源:百度知道 编辑:UC知道 时间:2024/06/24 10:19:19
#include<iostream>
using namespace std;
class Point
{

public:
Point(int x=0,int y=0)
{
_x=x;
_y=y;
}
Point& operator++()
{
_x++;
_y++;
return *this;
}
Point operator++(int)
{
Point pt;
pt=*this;
_x++;
_y++;
return pt;
}
int getx()
{
return _x;
}
int gety()
{
return _y;
}

private:
int _x,_y;

};
void main()
{
Point pt(0,0);
pt++;
cout<<pt.getx()<<" ";
cout<<pt.gety()<<endl;
cout<<(pt++).getx()<<" ";
cout<<(pt++).gety()<<endl;
cout<<(++pt).getx()<<" ";
cout<<(++pt).gety()<<endl;

你问题是什么。
程序没问题啊
运行出来结果是
1 1
1 2
4 5.

#include<iostream>
using namespace std;
class Point
{

public:
Point(int x=0,int y=0)
{
_x=x;
_y=y;
}
Point& operator++()
{
_x++;
_y++;
return *this;
}
Point operator++(int)
{
Point pt;
pt=*this;
_x++;
_y++;
return pt;
}
int getx()
{
return _x;
}
int gety()
{
return _y;
}

private:
int _x,_y;

};
void main()
{
Point pt(0,0);
pt++;
cout<<pt.getx()<<" ";
cout<<pt.gety()<<endl;
cout<<(pt++).getx()<<" ";
cout<<(pt++).gety()<<endl;
cout<<(++pt).getx()<<" ";
cout<<(++pt).gety()<<endl;
}
请问你的问题是

1 1
1 2
4 5
对的啊~