小白求助 一元运算符重载的*this问题
#define _CRT_SECURE_NO_WARNINGS#include "iostream"
using std::endl;
using std::cout;
using std::cin;
class Complex
{
private:
int a;
int b;
public:
Complex(int a, int b)
{
this->a = a;
this->b = b;
}
public:
void printTest()
{
cout << this->a << " " << this->b << endl;
}
public:
Complex& operator--()
{
this->a--;
this->b--; //问题2:返回变量本身是啥意思?这个引用不是相当于Complex* const operator- -() 吗?相当于返回this指针
return *this;//问题1: 这个返回*this是返回一个变量标识的空间吗?相当于返回后面的c1吗?有点迷糊,为啥 - -c1返回本身的空间?
}
};
void main()
{
Complex c1(11, 22);
--c1;
c1.printTest();
system("pause");
}