C++如何调用父母的好友功能?
有一个基类和一个派生类。派生公共继承Base。基类实现了友元函数 bool operator==(const Base& lhs,const Base& rhs) const; 我正在实现 Derive 类,它还需要实现 bool operator==(const Derive&lhs, const Derive&rhs) const;现在我的问题是我不知道如何在我的operator==函数中调用父母的operator==函数。 Base类的operator==不属于base,所以我不能简单地使用Base::operator==。谢谢。
There is a Base class and a Derive class. Derive public inherit Base. The base class has implemented a friend function bool operator==(const Base& lhs,const Base& rhs) const;
I am implementing the Derive class, which also need to implement bool operator==(const Derive& lhs, const Derive& rhs) const; Now my problem is that I do not know how to call the parents's operator== function in my operator== function. The operator== for Base class dose not belong to base, so i cannot simply use Base::operator==. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将引用绑定到
Base
子对象,并将它们与正常的运算符语法进行比较。示例:警告:如果您不小心将
Base
与Derive
进行比较,这样的设置将会默默地进行切片。如果基类必须具有可比性,那么可能值得建立一个虚拟比较机制。Bind references to the
Base
subobjects, and compare them with normal operator syntax. An example:Warning: A setup like this will silently slice if you accidentally compare a
Base
to aDerive
. If the base class must be comparable, it might be worth setting up a virtual comparison mechanism.