作者ric2k1 (Ric)
看板EE_DSnP
標題Re: [問題] 為什麼沒有virtual constructor,virtua …
時間Sun Dec 16 22:33:01 2007
※ 引述《popo4231 (小泰)》之銘言:
: 如題...
virtual function is used by derived class to override the definition of the
function in the parent class.
However, when an object is being created, e.g.
Parent *p = new Child; // 看不懂? 下一章會教到...
The parent constructor will be called first anyway, and then
the derived class constructor (Child) will be called.
Besides, the "virtual table pointer" of the derived class object was assigned
when the derived class constructor is called, so there is no need to
declare the parent class constructor since there is NO WAY for the child class
object to know which virtual function to call (no virtual table pointer...).
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.134.219