Modern C++ rarely use subclassing¹. The default in my code should certainly be non-virtual.
Someone already mentioned the performance issue. This applies both to run-time but also memory. Imagine we introduce a new type called ‘point’ representing a 2D point. We may have millions of these and we may store them in vectors, here we do not want to pay for the memory overhead of adding a jump table to each point in this vector (or initializing such pointer when constructing points, going through the jump table when doing “simple” math with the points etc.).
¹ Although the substitute for subclassing to achieve polymorphism in C++ tend to be generic programming, many OO languages are advocating composition over inheritance.
Comments
Modern C++ rarely use subclassing¹. The default in my code should certainly be non-virtual.
Someone already mentioned the performance issue. This applies both to run-time but also memory. Imagine we introduce a new type called ‘point’ representing a 2D point. We may have millions of these and we may store them in vectors, here we do not want to pay for the memory overhead of adding a jump table to each point in this vector (or initializing such pointer when constructing points, going through the jump table when doing “simple” math with the points etc.).
¹ Although the substitute for subclassing to achieve polymorphism in C++ tend to be generic programming, many OO languages are advocating composition over inheritance.