Hi.
Is there an advantage to using dynamic binding instead of static binding?
I have both Deitel & Deitel C++ How to Program and Stroustrup's Special Edition. I read all of the first book and finished chapter fifteen of Stroustrup. So I understand virtual functions and virtual base. However, I am not to the point where I can implement virtual functions and virtual base without asking: How do you implement them effectively?
For example, "virtual" only works for pointer and reference. That is completely conceivable. However, it seems you have to declare an object of a derived class and then *cast* a new class from the base class to the derive class just to get it working right.
-----------------
classDerived cDerived = new classDerived;
classBase *cBase = &cDerived;
-----------------
The example above comes straight from Deitel & Deitel. So everything looks okay. What is the point of declaring two separate classes? I understand that the use of "virtual," but I do not understand the performance of "virtual" if you have to declare an object of the derived class and an object of the base class. Under what specific situation do you implement dynamic binding? Please be very specific because I found that neither Deitel & Deitel nor Stroustrup give a convincing example of dynamic binding.
Lastly, I too want to implement dynimic binding if it is possible to declare *one* object of either the base class or the derived class. The following is *not correct*:
------------------------
classBase *cDynamic = new classDerived
------------------------
In other words, *virtual* would be great if there is a way to use it without having to declare two seperate classes like the example from Deitel & Deitel.
Thanks,
Kuphryn