C ++ runtime switching
I am reading in my tutorial about virtual functions in C ++ and my book does not elaborate on what is runtime binding. It doesn't give me any information as to why I need runtime binding.
Perhaps the good people at SO can provide me with some links or information?
Thanks:]
How about this ?; D
In all seriousness though ... the first link looks decent.
Here's a preview:
The most important reason a virtual function will be used is to have different functionality in a derived class. The difference between a non-virtual member function and a virtual member function is that 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. When 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, a programmer can use one interface for several implementations. This capability also allows you to create class libraries that establish standard interfaces, but allow the programmer to tailor those interfaces to any unique implementation situations that might arise. One of the most popular libraries is the Microsoft Foundation Classes (MFC) library, which provides the interfaces required for programming in the Windows environment.This library frees the programmer from having to reinvent Windows interfaces, instead allowing him or her to focus on the concrete implementation of those interfaces.
a source to share
The simplest form of runtime binding is polymorphism. In the C ++ context, polymorphism is achieved through virtual functions. The main purpose of this is to call methods on instances of derived classes through a pointer or reference to the base class.
Googling virtual functions should give you a lot of good results on how and why to do it.
a source to share
Read Uncle Bobs's article on SOLID Object Oriented Design principles: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
Obviously they are not related to runtime binding, but they describe the type of design problem you are trying to solve that requires you to use runtime binding.
I think the article on open closed principle best demonstrates (again, the article is not related to runtime binding) when you need to do this: http://www.objectmentor.com/resources/articles/ocp.pdf
a source to share