Redefining & Overriding (Non-virtual & Virtual)

I would like to know the difference between

Redefining & Overriding (Non-virtual & Virtual)

Consider 2 codes :

1
2
3
4
5
6
7
8
double Sale::savings(const Sale& other) const
{
    return (bill( ) - other.bill( ));
}
bool operator < (const Sale& first, const Sale& second)
{
    return (first.bill( ) < second.bill( ));
}


what if bill is inherited in a derived class discountsale with a different bill() version than just return original price from class Sale.
a) bill() is virtual function
b) bill() is non-virtual

Thanks in advance.
The difference is evident in objects allocated in stack (with new). To be more specific let's say we have 2 objects:

one from the base class B with a virtual function vfunc() and
one from the derived class D with a different virtual function [code]vfunc().

The compiler recognized the real type of each object and calls the correct function.

If the functions weren't virtual then only the static type of each object would be used:

If a base* B is used then ALWAYS the function of the base class will be called regardless of the dynamic type of B (B could point to a base object or a derived object)
Topic archived. No new replies allowed.