[問題] C++ early binding 邏輯觀念問題
開發平台(Platform): Visual studio 2010
問題(Question):
請問這裡前輩們
我只懂early binding這名詞
不太清楚這觀念,想問的是
1.物件fa的型態是FeetArea
為什麼fa.getArea();這行總是執行InchArea類別裡的int getlength()這函示???
2.程式碼二不是很完全,因只想裡解觀念問題
func(*pia);與func(*pfa);
都是呼叫 FeetArea::getlength();
而不是InchArea::getlength();
這是為什麼?????
程式碼(Code):
程式碼一
class InchArea
{
int getlength(){
return inch;
}
int getArea(){
return int(pow(getlength(), 2));
}
}
class FeetArea:public InchArea
{
int getlength(){
return inch;
}
}
void main (void)
{
FeetArea fa(8);
fa.getArea();
}
========分隔線===========
程式碼二
http://codepad.org/M3H6Vqp5
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.36.196.72
→
09/15 01:07, , 1F
09/15 01:07, 1F
→
09/15 20:45, , 2F
09/15 20:45, 2F
→
09/15 21:01, , 3F
09/15 21:01, 3F
→
09/15 21:02, , 4F
09/15 21:02, 4F
→
09/17 15:25, , 5F
09/17 15:25, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章