Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class with both abstract and virtual methods

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)

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?

like image 346
Dollarslice Avatar asked Jun 21 '26 10:06

Dollarslice


2 Answers

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.

like image 122
Cat Plus Plus Avatar answered Jun 22 '26 23:06

Cat Plus Plus


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

like image 34
ks1322 Avatar answered Jun 22 '26 23:06

ks1322



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!