运算符重载
运算符重载:对已有的运算符重新定义,赋予其另一种功能,以适应不同的数据类型加号运算符重载
作用:实现两个自定义类型的相加运算
#includeusing namespace std;class Person{private: int m_A; int m_B;public: Person(int A, int B) { m_A = A; m_B = B; } Person() { } //成员函数完成加号运算符重载 /*Person operator+(Person& p) { Person temp; temp.m_A = this->m_A + p.m_A; temp.m_B = this->m_B + p.m_B; return temp; }*/ void print() { cout
页:
[1]