Dynamic typing goes against C++'s philosophy of strong static typing, so it should indeed be used sparingly. However, there are situations where the flexibility is necessary:
However, even in these cases, try to constrain the use of dynamic typing as much as possible. Use templates, inheritance, or variant where you can. Reserve void* and std::any for when the type truly cannot be known at compile time.
Answers to questions are automatically generated and may not have been reviewed.
std::any
Learn how to use void pointers and std::any
to implement unconstrained dynamic types, and understand when they should be used