看板java
标 题Re: [问题] 请问toString的观念
发信站KKCITY (Fri Apr 28 09:50:54 2006)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!bbs.ee.ntu!news.kkcity.com.
※ 引述《adrianshum》之铭言:
> ※ 引述《pshuang》之铭言:
> > 不是 RTTI的话,
> > virtual function table 就要依靠 compiler 帮忙建立吧!
> > 那 obj.toString() 是 compiler 时期就决定该呼叫哪一个class的method 吗?
> 建议你去看看有关 virtual function table 那些东西的概念吧...
> 尝试用抽象一点的方法说一说
> 当你的 object (叫 A class 吧) 被建立时, 其 vftab 也会被建立.
以上是 compiler 时期建立的。
> 当中有一个entry 是 "toString" 而该 entry 则指着 A 的 toString
> 而当一个 Object 的 reference 指着一个实体时, invoke
> obj.toString() 时, compiler 并不是把这句译成 invoke A 的 toString
> (因为这是不可能的, 这是 runtime 才能决定的, 不然就没有了 polymorphism
> 的用意了), 而实际的动作, 是去到该 object 的 vftab 中, 找出 "toString"
> 的 entry, 然後 invoke 该entry 所指着的 method.
当一个 instance 被宣告并定义时,它的 type 就被决定了,
也代表相关的 virtual function 已经指定到该呼叫的地方(compiler 时即以决定)。
那麽,这该算是由 compiler 做好多型的mapping吗 ?
> 大概的概念是这样.
> Alien
--
┌─────◆KKCITY◆─────┐ ◢
◤ 找歌最方便 KKBOX 歌词搜寻!!
│ bbs.kkcity.com.tw │ \^_^ / ★http://www.kkbox.com.tw★
└──《From:61.30.73.247
》──┘ ◤ 唱片公司授权,音乐尽情下载
--