作者meanid (meanid)
看板EE_DSnP
標題[問題] ifstream問題
時間Thu Nov 3 04:23:35 2011
再寫openDofile的時候
_dofile = new ifstream(dof.c_str);
然後要用_dofile呼叫她的member function的時候,像是
_dofile.eof() 或是 _dofile.close()
都會compile錯誤:request member for 'close' ...省略...'_dofile', which is
non_class type "std::ifstream"
但是如果改成這樣呼叫:_dofile->eof(), 就可以了耶
為什麼會這樣啊??
網路和書的參考資料都是_dofile.eof()呼叫的
_dofile是pointer??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.245.82
1F:推 simpdanny:_dofile 的type是 ifstream * 所以要_dofile->close(); 11/03 04:25
2F:→ simpdanny:可以去看cmdParser.cpp 的_dofile declaration 11/03 04:25
所以第一行應該寫成ifstream * _dofile = new ifstream(dof.c_str); 嗎?
還是說_dofile = new ifstream(dof.c_str);就已經讓_dofile 的type是ifstream *了?
※ 編輯: meanid 來自: 140.112.245.82 (11/03 04:34)
3F:推 simpdanny:你的理解是正確的. new回傳的是 address 11/03 05:04
4F:推 wmin0:找一下_dofile 這個member data在哪裡被宣告成什麼樣子吧 11/03 06:40
5F:推 victoret:看一下 .h 檔裡 _dofile 的 type 是啥 11/03 08:13