[問題] non-class type

看板C_and_CPP作者 (B.S)時間16年前 (2009/12/30 10:26), 編輯推噓4(409)
留言13則, 6人參與, 最新討論串1/1
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 ) ( 未必需要依照此格式,文章條理清楚即可 ) 遇到的問題: (題意請描述清楚) Compile時出現 request for member 'scan' in 'lexer', which is of non-class type 'Lexer()()' 希望得到的正確結果: 能正確編譯 程式跑出來的錯誤結果: 開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux) Windows XP Code::Blocks GNU GCC Compiler 有問題的code: (請善用置底文標色功能) #include <iostream> using namespace std; class Token{ public: int tag; Token(int t) { tag = t; } string toString() { string s = "" + (char)tag; return s; } }; class Lexer{ public: int line; char peek; Lexer() { line = 1; peek = ' '; } Token scan() { Token tok(peek); peek = ' '; return tok; } }; int main() { Lexer lexer(); while(1){ Token t = lexer.scan(); //無法compile處 cout << t.toString() << endl; } } 補充說明: 這是程式的一小部份。 這種情況下怎麼樣都會出現上述狀況, 無論怎麼修改都不是orz Google過了些資料也都無法解 囧 請各位高手幫忙了<(_ _)> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.117.199.88 ※ 編輯: BSpowerx 來自: 140.117.199.88 (12/30 10:29)

12/30 10:30, , 1F
string還沒include吧
12/30 10:30, 1F

12/30 10:33, , 2F
iostream裡面就有std::string了
12/30 10:33, 2F

12/30 10:40, , 3F
#include <string> +1.
12/30 10:40, 3F

12/30 10:43, , 4F
Lexer lexer;
12/30 10:43, 4F

12/30 10:45, , 5F
喔~~我看到你的訊息了 他把他以為是func
12/30 10:45, 5F

12/30 10:48, , 6F
Lexer lexer(); 改成 Lexer lexer; 後換原始的大程式別的
12/30 10:48, 6F

12/30 10:48, , 7F
地方出錯 囧
12/30 10:48, 7F

12/30 10:49, , 8F
error: aggregate 'Lexer lexer' has incomplete type
12/30 10:49, 8F

12/30 10:49, , 9F
and cannot be defined
12/30 10:49, 9F

12/30 10:58, , 10F
好像找到問題所在了@@ 再研究看看
12/30 10:58, 10F

12/30 14:48, , 11F
看起來好像是某江老師的作業...
12/30 14:48, 11F

12/30 14:49, , 12F
就是某江老師的作業沒錯...我也正在死命寫中XD
12/30 14:49, 12F

12/31 02:25, , 13F
就是某江老師的作業沒錯...
12/31 02:25, 13F
文章代碼(AID): #1BEhf7R7 (C_and_CPP)