# 运算符重载里面程序运行细节

class Integer
{
public:
Integer(int num = 0);
~Integer();
Integer(const Integer& other);
Integer &operator=(int num);
Integer &operator=(Integer &other);
friend Integer operator+(int num, Integer &me);
Integer operator+(int num);
int GetNum();
private:
int _num;
};

Integer::Integer(int num) :_num(num)
{
std::cout << "Integer(int)" << _num  << std::endl;
}

Integer::~Integer()
{
std::cout << "~Integer()" << std::endl;
}

Integer::Integer(const Integer & other)
{
_num = other._num;
std::cout << "Integer(Integer&)" << _num << std::endl;
}

Integer & Integer::operator=(int num)
{
_num = num;
std::cout << "operator=(int)" << _num <<std::endl;
return *this;
}

Integer & Integer::operator=(Integer & other)
{
_num = other._num;
std::cout << "operator=(Integer&)" << _num << std::endl;
return *this;
}

Integer Integer::operator+(int num)
{
Integer temp = _num;
temp._num += num;
std::cout << "operator+(int)" << temp._num << std::endl;
return temp;
}

int Integer::GetNum()
{
return _num;
}

Integer operator+(int num, Integer & me)
{
Integer temp = me._num;
temp._num += num;
std::cout << "operator+(friend&)" << temp._num << std::endl;
return temp;
}

int main()
{
Integer demo = 10, other ;
other = 100 + demo + 200;
return 0;
}

int main()
{
Integer demo = 10;
Integer other = 100 + demo + 200;
return 0;
}

Integer other = 100 + demo + 100；

Integer& operator++();
Integer operator++(int);

Integer & Integer::operator++()
{
_num += 1;
return *this;
}

Integer Integer::operator++(int)
{
Integer temp = *this;
_num += 1;
return temp;
}

int n1 = 10;
int n2 = n1++;

friend std::ostream & operator<<(std::ostream & lhs, const Integer & rhs)
{
lhs << rhs._num;
return lhs;
}

friend std::istream& operator>>(std::istream &lhs, Integer &rhs)
{
lhs >> rhs._num;
return lhs;
}

#### 运算符的重载程序在VC6.0中遇到的问题

2017-09-13 20:00:07

#### C++中的运算符重载-1

2016-05-11 21:36:14

#### ProcessMonitor程序操作监控

2012年10月22日 962KB 下载

#### 【C++ primer在练习中体悟】 C++中二元运算符重载需要使用friend的原因

2016-11-28 20:58:51

#### 294534交易论坛代码php+mysql

2009年08月17日 450KB 下载

#### 【C++面向对象】C++中运算符重载的两种方式

2016-10-28 11:21:49

#### C++中的重载运算符、继承、封装、多态讲解（进阶篇）

2016-07-15 10:16:31

#### 深入解析C++输入输出运算符重载

2012-05-07 22:42:32

#### 头文件的包含及运算符重载

2014-01-29 17:06:38

#### 倒茶学问（需注意~~有时候细节决定成败！！）

2010-07-09 10:41:00