[問題] class和reinterpret_cast運用看不懂
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
我現在在看Source code,其中這邊看不懂...QQ
麻煩前輩指點了
--------------------
問題一開始先說明有一個class名為Timebuffer,其有一個template T,如下網址
Timebuffer http://codepad.org/2SALFOxp
然後在其他class裡面建立一個Timebuffer成員,如下
TimeBuffer<FetchStruct> fetchQueue; (1)
隨後在同個class裡面有叫用到Timebuffer 裡面的member function,如下
fetchQueue.advance();
而這個function可以在上面Timebuffer 網頁中第179行看到
其中第187行
(reinterpret_cast<T *> (index[ptr]) ) -> ~T(); (2)
這邊有將一個index[ptr]內容強轉態為 T *型態
而這個型態可以看到上面(1)的地方,是為一個FetchStruct的東西
可以看到 http://codepad.org/XXtdcI5S 裡面的第93行
typedef DefaultFetchDefaultDecode<Impl> FetchStruct;
可以知道他前身是DefaultFetchDefaultDecode,
而這個又可以在http://codepad.org/W3Ql7bgu 第60行的地方找到
template<class Impl>
struct DefaultFetchDefaultDecode {
可以發現他是一個structure,那麼...
回到上面(2)的地方,
他既然強轉態成 T *,也就是DefaultFetchDefaultDecode structure型態
那為什麼會有解構子 ~T() 呢?
亦或是,我也在該個structure中看不到解構的動作?
不知道上述說明哪裡不正確
在這方面觀念很薄弱,希望前輩們可以指點指點!!
謝謝 :)
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.187.212
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1428147580.A.6D3.html
→
04/04 19:55, , 1F
04/04 19:55, 1F
→
04/04 19:56, , 2F
04/04 19:56, 2F
→
04/04 19:57, , 3F
04/04 19:57, 3F
→
04/04 19:57, , 4F
04/04 19:57, 4F
我看這邊也看的有點疼
placement new我也不知道是什麼,立馬來看一下
而自動產生的default destructor的確是有
我用GDB去看,有下面這一行
DefaultFetchDefaultDecode<O3CPUImpl>::~DefaultFetchDefaultDecode
(this=0x59bef40, __in_chrg=<optimized out>) at build/ARM/cpu/o3/comm.hh:60
但是原始的地方沒有定義destructor,那怎麼可以執行 ~T()
還是這裡的 ~DefaultFetchDefaultDecode 不等於 ~T() 呢?
謝謝~
※ 編輯: smilekerker (140.116.187.212), 04/04/2015 20:18:54
推
04/04 20:34, , 5F
04/04 20:34, 5F
→
04/04 20:43, , 6F
04/04 20:43, 6F
→
04/04 20:44, , 7F
04/04 20:44, 7F
推
04/04 20:48, , 8F
04/04 20:48, 8F
→
04/04 20:49, , 9F
04/04 20:49, 9F
→
04/04 20:50, , 10F
04/04 20:50, 10F
→
04/04 20:50, , 11F
04/04 20:50, 11F
→
04/04 22:02, , 12F
04/04 22:02, 12F
→
04/04 22:46, , 13F
04/04 22:46, 13F
→
04/04 22:46, , 14F
04/04 22:46, 14F
→
04/05 01:54, , 15F
04/05 01:54, 15F