开发者

class with both abstract and virtual methods

Can I write a class which 开发者_如何学Pythonhas virtual methods - (which can be overridden but have a default behaviour) and also abstract methods - (which have to be overridden)

Can I have a definition in which I define implementations for the virtuals but not the abstracts?

Additionally can I create abstract methods that don't have an implementation in a non abstract / pure virtual class?


Can I write a class which has virtual methods - (which can be overridden but have a default behaviour) and also abstract methods - (which have to be overridden)

Yes.

Can I have a definition in which I define implementations for the virtuals but not the abstracts?

Yes.

Additionally can I create abstract methods that don't have an implementation in a non abstract / pure virtual class?

No. The presence of pure virtual members prohibits you from creating class instances, i.e. makes the class abstract.


It' s ok to have some virtual methods with reasonable default implementation, while other pure virtual methods have to be implemented in derived classes.


Yes you can. If there's a pure virtual method to your class then class will be abstract and can't be instantiated, but you can implement all the rest of the methods (virtual or otherwise) and the inheriting classes would be able to access them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜