美文网首页程序员
[C++进阶]在operator=中处理"自我赋值"

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

作者: 小鱼号的代码日记 | 来源:发表于2020-09-06 23:14 被阅读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个具体做法
*****/

相关文章

网友评论

    本文标题:[C++进阶]在operator=中处理"自我赋值"

    本文链接:https://www.haomeiwen.com/subject/nrihektx.html