是否应该将实现接口类的纯虚方法的方法声明为虚拟? [英] Should methods that implement pure virtual methods of an interface class be declared virtual as well?

查看:256
本文介绍了是否应该将实现接口类的纯虚方法的方法声明为虚拟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个问题有不同的意见。让我们假设我有一个接口类有一堆纯虚拟方法。我在实现接口的类中实现这些方法,我不期望从实现中派生。



是否需要将实现中的方法声明为virtual以及?如果是,为什么?

解决方案

否 - 在基类中声明为virtual的每个函数方法都将在所有派生类中都是虚拟的。 / p>

但是好的编码实践告诉我们声明这些方法virtual。


I read different opinions about this question. Let's say I have an interface class with a bunch of pure virtual methods. I implement those methods in a class that implements the interface and I do not expect to derive from the implementation.

Is there a need for declaring the methods in the implementation as virtual as well? If yes, why?

解决方案

No - every function method declared virtual in the base class will be virtual in all derived classes.

But good coding practices are telling to declare those methods virtual.

这篇关于是否应该将实现接口类的纯虚方法的方法声明为虚拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆