程序员

[C++进阶]在operator=中处理"自我赋值"

2020-09-06  本文已影响0人  小鱼号的代码日记
/***************************
effectivre c++
改善编程与设计的55个具体做法
条款11:在operator=中处理"自我赋值"
 ---------小鱼号的代码日记--------------
****************************/

class widget
{
public:
    widget& operator =(const widget& rhs)
    {
        if(this == &rhs)
            return *this;
        ///....
        ///
        return *this;
    }

    widget& operator +=(const widget& rhs)
    {
        return *this;
    }
};
#include <QCoreApplication>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    return a.exec();
}

/*****
内容选自:
effectivre c++
改善程序与设计的55个具体做法
*****/
上一篇 下一篇

猜你喜欢

热点阅读