找回密码
 立即注册
首页 业界区 业界 运算符重载

运算符重载

赀倦 2025-6-8 12:05:16
运算符重载:对已有的运算符重新定义,赋予其另一种功能,以适应不同的数据类型
加号运算符重载

作用:实现两个自定义类型的相加运算
[code]#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
您需要登录后才可以回帖 登录 | 立即注册