作者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