C++ 多型
阿新 • • 發佈:2020-07-23
多型按字面的意思就是多種形態。當類之間存在層次結構,並且類之間是通過繼承關聯時,就會用到多型。
C++ 多型意味著呼叫成員函式時,會根據呼叫函式的物件的型別來執行不同的函式。
下面的例項中,基類 Shape 被派生為兩個類,如下所示:
多型按字面的意思就是多種形態。當類之間存在層次結構,並且類之間是通過繼承關聯時,就會用到多型。
C++ 多型意味著呼叫成員函式時,會根據呼叫函式的物件的型別來執行不同的函式。
下面的例項中,基類 Shape 被派生為兩個類,如下所示: