-inherit 變數與函式
-create 新的變數與函式
- is-a 的關係
無法繼承
-建構子與解構子
-friend(爸爸的朋友未必是兒子的朋友)
-static
-Overloading assignment operators and copy constructors
public inheritance
-can't access the private members of the base class
-member functions of the derived class can access public and protected members of the base class
最常見的繼承,子類別可以跟平常一樣使用父類別
private inheritance
-can't access the private members of the base class
protected inheritance
–member functions of the derived class still can access public and protected members of the base class directly
–cannot access private members of the base class
小結:
在base class裡的public跟protected members的存取權會隨著繼承方式是哪種而變成哪種,至於private members不管用哪種方式繼承都不可被存取。
public inheritance
-can't access the private members of the base class
-member functions of the derived class can access public and protected members of the base class
最常見的繼承,子類別可以跟平常一樣使用父類別
private inheritance
-can't access the private members of the base class
-member functions of the derived class can access public and protected members of the base class
An object of the derived class cannot access any member (including public, protected and private) of the base class
–member functions of the derived class still can access public and protected members of the base class directly
–cannot access private members of the base class
小結:
在base class裡的public跟protected members的存取權會隨著繼承方式是哪種而變成哪種,至於private members不管用哪種方式繼承都不可被存取。
overload operator=
CDerived& CDerived::operator = (const CDerived& rHand) {
CBase::operator=(rHand);
//...
}
copy constructor
Cderived::CDerived(const CDerived& obj):CBase(obj) {
//...
}
觀念: 繼承來的就呼叫原本的,新的自己處理
沒有留言:
張貼留言