lab8_1.cpp
来自「该程序包含了c++中函数的多态性」· C++ 代码 · 共 54 行
CPP
54 行
// lab8_1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
class Point
{
public:
Point(int x=0,int y=0)
{_x=x;_y=y;}
operator ++();
operator ++(int);
operator --();
operator --(int);
void display();
private:
int _x, _y;
};
void Point::display()
{
cout<<"_x="<<_x<<","<<"_y="<<_y<<endl;
}
Point::operator ++()
{
return ++_x;
return ++_y;
}
Point::operator ++(int)
{
return _x++;
return _y++;
}
Point::operator --()
{
return --_x;
return --_y;
}
Point::operator --(int)
{
return _x--;
return _y--;
}
void main()
{
Point p(2,2);
++p;
p.display();
p++;
p.display();
--p;
p.display();
p--;
p.display();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?