[問題] C++編譯出現錯誤訊息

看板Programming作者 (:))時間17年前 (2008/04/18 11:49), 編輯推噓2(207)
留言9則, 3人參與, 最新討論串1/1
※ [本文轉錄自 C_and_CPP 看板] 作者: typecommand (:)) 看板: C_and_CPP 標題: [問題] C++編譯出現錯誤訊息 時間: Fri Apr 18 19:48:47 2008 已自行上google找答案,有找到可能的解答,但還是看不懂, 所以只好上來請教高手 http://www.cs.ucla.edu/~shinnerl/cs31/x/simpleIO/noStreamCopy.cpp 這是我的部份程式碼 (simstream.h) class SimS { public: SimS (ostream &s); ~SimS (void); private: ofstream fp; ostream stream; friend class SimStream; }; (simstream.cpp) SimS::SimS (ostream &s) { rc = 1; stream = s; <------這行會出錯,錯誤訊息如下 is_opened = 0; } simstream.cpp: In method `ostream &ostream::operator= (ostream &)': /usr/include/g++-3/streambuf.h:127: `ios &ios::operator= (ios &)' is private simstream.cpp:19: within this context 懇請高手能給我一點方向,因為我這問題卡很久了,先謝謝了。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.136.149.183 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.136.149.183

04/18 20:08, , 1F
simstream.c
04/18 20:08, 1F

04/18 20:08, , 2F
改副檔名為cpp吧
04/18 20:08, 2F

04/18 20:10, , 3F
啊. 因為他不允許你使用operator=
04/18 20:10, 3F
※ 編輯: typecommand 來自: 140.136.149.183 (04/18 20:22) ※ 編輯: typecommand 來自: 140.136.149.183 (04/18 20:23)

04/18 20:23, , 4F
請教1F大大有什麼方法可解嗎?謝謝
04/18 20:23, 4F

04/18 20:25, , 5F
讓你的member也是reference
04/18 20:25, 5F

04/18 20:26, , 6F
用initialize list初始化ostream
04/18 20:26, 6F

04/18 20:26, , 7F
二樓講了阿 XD 改副檔名為cpp吧
04/18 20:26, 7F

04/18 21:30, , 8F
回覆樓上,我改成cpp問題依舊,謝謝
04/18 21:30, 8F

04/18 21:53, , 9F
感謝s大提供的建議,我馬上試看看
04/18 21:53, 9F
文章代碼(AID): #1828grVr (Programming)