From what I’ve read, virtual functions are functions in the base class that you can override in its derived classes.
But earlier, when learning about basic inheritance, I was able to override base functions in derived classes without using virtual.
What am I missing here? I know there is more to virtual functions, and it seems to be important so I want to be clear on what it is exactly.
Without
virtualyou get "early binding". Which implementation of the method is used gets decided at compile time based on the type of the pointer that you call through.With
virtualyou get "late binding". Which implementation of the method is used gets decided at run time based on the type of the pointed-to object – what it was originally constructed as. This is not necessarily what you’d think based on the type of the pointer that points to that object.See Also