|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#define _CRT_SECURE_NO_WARNINGS
#include "iostream"
using std::cout;
using std::cin;
using std::endl;
class Complex
{
private:
int a;
int b;
public:
Complex(int a, int b)
{
this->a = a;
this->b = b;
}
public:
void printCom()
{
cout << this->a << " " << this->b << endl;
}
public:
friend Complex& operator++(Complex &c);
public:
Complex& operator--()
{
this->a--;
this->b--;
return *this;
}
};
Complex& operator++(Complex &c)
{
c.a++;
c.b++;
return c;
}
void main()
{
Complex c(11, 22);
++c;
c.printCom();
--c;
c.printCom();
system("pause");
}
问题:Complex& 返回一个引用究竟是啥子意思?为啥Complex& 返回的是c 有时返回*this *this应该是对象吧 |
|