天天看點

OOP: An Overview【c++ primer】

Inheritance :

Inheritance lets us define classes that model relationships among types, sharing what is common and

specializing only that which is inherently different.

那麼derived class 就有兩種選擇,1 。 和base class 有一樣的opration 2 。與base class 不一樣的,可以自己redefine 的opration。 對于derived class ,它可以redefine 的opration 是被base class 标志為virtual 的operation。

Dynamic Binding : 

Dynamic binding lets us write programs that use objects of any type in an inheritance hierarchy without caring about the objects' specific types 。

In C++, dynamic binding happens when a virtual function is called 

hrough a reference (or a pointer) to a base class. The fact that a 

reference (or pointer) might refer to either a base- or a derivedclass  

object is the key to dynamic binding. Calls to virtual functions  

made through a reference (or pointer) are resolved at run time: The

function that is called is the one defined by the actual type of the  

object to which the reference (or pointer) refers.