本文介绍了基类的调用操作符...安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下模式确定/安全吗?还是有什么缺点?
(我也用于等号运算符)

Is following pattern ok/safe ? Or are there any shortcomings ?(I also use it for equality operators)

Derived& operator=(const Derived& rhs)
{
    static_cast<Base&>(*this) = rhs;
    // ... copy member variables of Derived
    return *this;
}


推荐答案

更多可读的IMHO通过名称调用基类:

This is fine, but it's a lot more readable IMHO to call the base-class by name:

Base::operator = (rhs);

这篇关于基类的调用操作符...安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 08:22