[問題] Template 特化
看板C_and_CPP (C/C++)作者ayumiQmazaky (拜託刪我 爛人)時間14年前 (2011/12/14 12:05)推噓2(2推 0噓 4→)留言6則, 5人參與討論串1/2 (看更多)
在簡單複習一下template的用法
http://hatsukiakio.blogspot.com/2009/05/c-template.html
這網頁介紹得不錯
但...
他最後一個例子
T*& operator[](int i){
static T* t=(T*)Base::elem(i);
return t;
}
我自己
無法認同他這樣寫是正確的, 也許是我觀念有誤
但是他這樣不是return 一個 pointer的 reference嗎
這樣我再[] = xxx 不就等於 對它內部的 static T* t操作 讓他指到別的地方
而不是真的在對他member作操作
請各位看一下
我覺得最後他扯到回傳static 的pointer的reference有點怪
應該有別的寫法吧
請教各位 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.147.15.66
→
12/14 12:13, , 1F
12/14 12:13, 1F
推
12/14 14:57, , 2F
12/14 14:57, 2F
→
12/14 17:23, , 3F
12/14 17:23, 3F
→
12/14 20:49, , 4F
12/14 20:49, 4F
→
12/14 22:34, , 5F
12/14 22:34, 5F
推
12/14 23:02, , 6F
12/14 23:02, 6F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章