Virtual vs. Nonvirtual Functions
A virtual function is one that can be overridden by a subclass and whose execution is determined at runtime. If a function is defined within a parent class and a function with the same name is defined in a child class, the child class’s function overrides the parent’s function.
Several popular programming models use this functionality in order to greatly simplify complex
programming tasks. To illustrate why this is useful, return to the socket example in Example 20-5. There, we have code that is going to
sendData over the network, and we want it to be able to send data via TCP and UDP. One
easy way to accomplish this is to create a parent class called
Socket with a virtual function called
sendData. Then we have ...