實驗4 繼承

2022-09-10 08:03:12 字數 2629 閱讀 9483

實驗任務2

歸納總結:當派生類與基類有同名成員時,直接呼叫會呼叫派生類中的成員,也可以使用二元作用於域分辨符來對基類的的成員進行呼叫,且基類不與繼承類函式構成過載。

相容性原則,派生類成員可以當作基類來使用但是只能使用繼承於基類的那一部分。

修改後

#include #include 

//definitation of graph

class

graph

};//

definition of rectangle, derived from graph

class rectangle : public

graph

};//

definition of circle, derived from graph

class circle : public

graph

};//

definitaion of fun(): as a call inte***ce

void fun(graph*ptr)

//test

intmain()

實驗任務3

odometers輸入-1後

實驗任務4

實驗4 繼承

任務二 未加virtual 加virtual之後 同名覆蓋原則 基類中的函式和派生類的函式重名時,若未強行指名,則通過派生類物件使用的是派生類的同名成員 二元作用域分辨符 當派生類與基類中有相同成員時,如果要通過派生類物件訪問基類中被隱藏的同名成員,可以用基類名和作用域分辨符來限定 型別相容原則 在...

實驗4 繼承

task2 原 include include 歸納總結 同名覆蓋原則 當派生類的函式名或者成員名與基類的函式名或成員名發生重複 哪怕它們形參列表不同 將自動隱藏其父類的同名函式或物件,要使用其父類對應的函式或成員需要用父類作用域來進行說明。二元作用域分辨符 即 是雙目運算子,常用於 類名 成員,表...

實驗4 繼承

task2.cpp include include definitation of graph class graph definition of rectangle,derived from graph class rectangle public graph definition of circ...