[問題] C++編譯error

看板C_and_CPP作者 (腦殘並不可恥)時間12年前 (2012/04/10 14:40), 編輯推噓0(005)
留言5則, 5人參與, 最新討論串1/1
大家好,小弟第一次寫C++,也是第一次使用C++ 2010 express, 目前只想讀入一個文字檔,但編譯遇到錯誤。 class Board { int dim; int ** cells; public: Board (int); ~Board(); string toString(); void set_square_value(int,int,int); int Board::get_square_value(int,int); static Board * fromFile(string); //fromFile是檔案讀取函式 bool checkForVictory(); int get_dim() {return dim;} }; 我宣告 133 Board * b = Board.fromFile("4x4_exam.txt"); 編譯錯誤是 1>..\..\..\..\NU\sudoku.cpp(133): warning C4832: token '.' is illegal after UDT 'Board' 1> ..\..\..\..\NU\sudoku.cpp(12) : see declaration of 'Board' 1>..\..\..\..\NU\sudoku.cpp(133): error C2275: 'Board' : illegal use of this type as an expression 1> ..\..\..\..\NU\sudoku.cpp(12) : see declaration of 'Board' 1>..\..\..\..\NU\sudoku.cpp(133): error C2228: left of '.fromFile' must have class/struct/union ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 請問有人知道是怎麼一回事嗎? 我查過書都找不到問題在哪。 拜託了...謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 165.124.211.107

04/10 14:42, , 1F
Board::fromFile
04/10 14:42, 1F

04/10 19:35, , 2F
"."的前方應該要是一個初始化過的物件...我記得是這樣
04/10 19:35, 2F

04/12 08:42, , 3F
感謝回答~ C++真的好難喔!!
04/12 08:42, 3F

04/12 12:47, , 4F
有什麼是簡單的嗎= =
04/12 12:47, 4F

04/12 14:20, , 5F
嘴泡很簡單,看看主管就知道
04/12 14:20, 5F
文章代碼(AID): #1FWzN4UY (C_and_CPP)