Static (early) vs dynamic (late) binding in C++

The difference between static and dynamic binding is that static occurs at compile time and dynamic occurs at runtime. Example of static is function and operator overloading, example of dynamic is virtual function.

Now I still not get it. In the example of dynamic binding at http://www.cplusplus.com/forum/general/63940/ the line "pBase->DoOperation();" demonstrates dynamic binding. Why can't I resolve the function call at compile time? I have all the info I need to see the "Derived::DoOperation()" is called.

Could somebody please show me more examples?
Last edited on
cuz pBase could be a base class that has 2000 'child' classes, and you cannot know which of these derived classes it is until you actually run, set a breakpoint on that line, then step into your "DoOperation()" method.

example:
http://www.tutorialspoint.com/cplusplus/cpp_polymorphism.htm

particularly this line:
shape->area();
Last edited on
Topic archived. No new replies allowed.