I have three classes, A, B, and C. B and C are derived from A. Both B and C need to implement a method F
. The code in B.F() is a subset of C.F().
- Is it a good way declare
A.F()
as a virtual function and defineB.F()
andC.F()
? There would be the same code in 2 methods, which I would like to avoid. What are the other possibilities? - Define
A.F()
with the common code and override it inC.F()
. While overriding how can the output of A.F() be used in C.F(), so that repeated code can be avoided?