⓪編著 :蕭沖


複習一下過去的學習。

當Base Class裡的method與Derive Class中的method形成Overload的情形時,Base中的那些同名method都會被Hide起來。若是試著去使用Base中的那些method時,就會產生error。但可以把instance upcast後使用那些Hide的method,然而這時候Derive中的那些method也會變成無法使用。這個規則無論是Overload一個Base的Virtual或是非Virtual的method都適用!

當Derive Class中Redefine(同名同signature) Base Class中的method時,若此base 的method是Virtual的,那就會產生Override(覆載)。但若base method非Virtual的,那就會產生Hide的情形。

Overload : 同名但不同簽名(signature)
Override : 同名同簽名的Virtual method被再定義

Pure Virtual method不可使用inline方式定義method,但可以使用外部定義的方式。這樣每個子類別就可以方便以Interface::method的方式直接取用。但一般來說是不會在interface上定義method的。
arrow
arrow
    全站熱搜

    aftcast 發表在 痞客邦 留言(0) 人氣()