------ polymorphism with static binding static binding

Static binding and dynamic binding
(a) classification of polymorphic (polymorphic: a reference or pointer to the parent of the child class object)
Static Polymorphism: compile time to determine the address calling function, early binding, static binding; op overloading, function overloading
dynamic polymorphism: run-time to determine the address of the calling function, late binding, dynamic binding; parent class virtual function, inheritance, and having a rewritable
(b) polymorphic analytical principle
(1) when the parent when there is a virtual function, it changes the internal configuration, a plurality of vfptr pointer (first 4 bytes) directed own virtual function table;
(2) inherited by subclasses, inherit and vfptr vftable (vtable) , become their own virtual function tables.
(3) constructor, the subclass will vfptr own virtual function table point;
(4) a subclass if rewriting occurs, to replace its own virtual function table virtual function.
(C) the multi-state case - Calculator Case
development principles - the principle of opening and closing (open for extension, but closed for modification)
using multi-state implementation, is conducive to the expansion, structural very good. (Bottom layer is designed to abstract)
(iv) abstract class (at least one pure virtual function)
abstract class that can not be instantiated;
if they are inherited, which must be rewritten pure virtual function;

Published 38 original articles · won praise 13 · views 4328

Guess you like

Origin blog.csdn.net/YanWenCheng_/article/details/103946999