OOP: An Overview【c++ primer】

    技术2022-05-20  53

    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.


    最新回复(0)