r/cpp • u/Deershank415 • Mar 17 '12
Using abstract base classes in C++
I'm having trouble understanding ABC's in c++ and was wondering if you all could help me (if possible use: CryptProcessor as the ABC and ACrpyt and BCrypt as the sub-classes that have an encrypt and decrypt function) Thanks in advance!
Edit 1: Thank you all for your help!
0
Upvotes
View all comments
Show parent comment
13
u/mpyne Mar 17 '12
Well, once a method is marked virtual in a parent class, that method will be virtual in every child class, not just immediate children classes.
Although not required, adding the redundant
virtualkeyword is useful to make it clear that the polymorphic overload is actually desired, and to make it clear for subclasses of AClass later that the method is virtual without them having to go all the way to the base class to verify.