Search code examples
c++bindingruntimevirtual

Run-Time Binding C++


I'm reading in my text book about virtual functions in C++ and my book doesn't elaborate on what exactly run-time binding is. It doesn't give me any information as to why I would need run-time binding.

Maybe the nice people at SO can provide me with some links or information?

Thanks :]


Solution

  • How about this one? ;D

    http://www.google.ca/search?hl=en&source=hp&q=virtual+function+runtime+binding+c%2B%2B&aq=f&aqi=&aql=&oq=&gs_rfai=

    In all seriousness though... the first link looks decent.

    Here's a preview:

    The most prominent reason why a virtual function will be used is to have a different functionality in the derived class. The difference between a non-virtual member function and a virtual member function is, the non-virtual member functions are resolved at compile time.

    And from another site:

    In large, complex programs, virtual functions allow the programmer to simplify the programming process. If used correctly, the base class will successfully define the interface of its derived classes. However, the program will leave the implementation of this interface up to the derived classes. Therefore, the programmer can use one interface for multiple implementations. This capability also allows for the creation of class libraries, which establish standard interfaces, but allow the programmer to tailor these interfaces to any unique implementation situations that may arise. One of the most popular libraries around is the Microsoft Foundation Classes (MFC) library, which provides the interfaces necessary for programming in the Windows environment. This library frees the programmer from having to reinvent the Windows interfaces, instead allowing him or her to focus on the specific implementation of these interfaces.