[問題] 回傳自定義型別指標(Be solved!)

看板C_and_CPP (C/C++)作者 (鏡水月影)時間14年前 (2011/10/05 16:19), 編輯推噓0(009)
留言9則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux NetBeans 7.0.1 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) None 問題(Question): 請問函數可以回傳自己定義的型別指標嗎? 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 以下是 main.cpp 的部份程式碼 #include "table_scan.h" struct tableList { int index; char keyword[100]; tableList *next; }; typedef tableList* tablePt; int main(int argc, char** argv) { tablePt table1 = ScanTable(1); //這行跳出'ScanTable' was not declared in this scope } main.cpp 到此結束 table_scan.h 由此開始 tablePt ScanTable(int list) { //這行跳出‘tablePt’ does not name a type tablePt temp = NULL; blablabla statement; return temp; } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.135.255.154

10/05 16:28, , 1F
請查詢 forward declaration
10/05 16:28, 1F

10/05 16:46, , 2F
直接把.h的function複製到main.cpp反而能通過compiler.......
10/05 16:46, 2F

10/05 16:47, , 3F
typedef tableList* tablePt;應該是放在table_scan.h
10/05 16:47, 3F

10/05 16:47, , 4F
這行吧?
10/05 16:47, 4F

10/05 16:48, , 5F
在table_scan.h時,它哪知道tablePt是什麼鳥
10/05 16:48, 5F

10/05 16:53, , 6F
原來如此 囧rz囧rz囧rz囧rz囧rz囧rz囧rz囧rz囧rz囧rz囧rz
10/05 16:53, 6F

10/05 18:16, , 7F
我以為你是說"函式內部定義的型別"...恐怖的問題
10/05 18:16, 7F

10/06 10:51, , 8F
有多恐怖@@?
10/06 10:51, 8F

10/06 11:04, , 9F
應該是沒幾個人可以回答的恐怖
10/06 11:04, 9F
文章代碼(AID): #1EZ1C9BV (C_and_CPP)
文章代碼(AID): #1EZ1C9BV (C_and_CPP)