![]() |
#2
家力掠2016-04-17 18:53
|

-----point.h
class Point
{
public:
Point();
Point(float x, float y);
~Point();
Point operator ++();
Point operator --();
private:
float x, y;
}
-----point.cpp
Point Point::operator ++()
{
this->x = this->x + 1;
this->y = this->y + 1;
return *this;
}
Point Point::operator --()
{
this->x = this->x - 1;
this->y = this->y - 1;
return *this;
}
------main.cpp
Point r5. r6;
r5 = p1++;
r6 = p1--;
class Point
{
public:
Point();
Point(float x, float y);
~Point();
Point operator ++();
Point operator --();
private:
float x, y;
}
-----point.cpp
Point Point::operator ++()
{
this->x = this->x + 1;
this->y = this->y + 1;
return *this;
}
Point Point::operator --()
{
this->x = this->x - 1;
this->y = this->y - 1;
return *this;
}
------main.cpp
Point r5. r6;
r5 = p1++;
r6 = p1--;
VS2015 错误:
1>c:\users\busters\documents\visual studio 2015\projects\c++作业\overload\overload\overload.cpp(14): error C2676: 二进制“++”:“Point”不定义该运算符或到预定义运算符可接收的类型的转换
1>c:\users\busters\documents\visual studio 2015\projects\c++作业\overload\overload\overload.cpp(15): error C2676: 二进制“--”:“Point”不定义该运算符或到预定义运算符可接收的类型的转换