Virtual functions are inappropriate here because the functions of the subclass are specific to these subclasses (for example, CourseStudent has a list of units, while ResearchStudent does not, so the implementation of the getUnits () function in ResearchStudent does not make sense at all)
I had a bit of reading on dynamic and static broadcasts ( cplusplus.com typecasting ), in which case I think static casting is more suitable.
The common drawback of static_cast is that it does not perform any checks at runtime to ensure that the object being passed to the subtype is actually a subtype, and not some other. In this case, I specifically check the type before I execute the type (using a private data element that is set in the constructor of the subclass and does not have a mutator), so as long as my check is good, there should be no problems with static casting, Static cast is more efficient because dynamic migration requires more runtime resources for type checking.
If there is a possibility that the member will not be the expected type, static casting will not be suitable, so I would go for dynamic casting (this is the purpose, therefore, after sending it, the code does not need to be supported, so there is no risk that someone will ruin it later) .
source share