看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Win 7 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) Dev-C++ 5.11 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 跟小弟之前問用 qsort 排序二維陣列類似, 只是這次換成排序 array 和 struct 想宣告一個 array, 元素都是 struct, 然後去做排序 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): prog.c: In function ‘compw’: prog.c:7:12: error: dereferencing pointer to incomplete type ‘struct data’ return (p1->x) - (p2->x); ^~ prog.c: In function ‘comph’: prog.c:13:12: error: dereferencing pointer to incomplete type ‘struct data’ return (p1->y) - (p2->y); 程式碼(Code):(請善用置底文網頁, 記得排版) https://ideone.com/QjGEGU 補充說明(Supplement): 看不懂哪裡出問題, 麻煩大家幫忙解惑. 感恩 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.224.163.247 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1505141531.A.BCF.html
stucode: compw 和 comph 看不到 struct data 的定義 09/11 22:58
Schottky: 把 struct data 的定義從 main 裡移到 compw() 之前 09/11 22:59
linshihhua: 謝謝, 想請問我試著在前面宣告函數的原型 09/11 23:09
linshihhua: 然後把函數搬到 main 的後面也會有問題 09/11 23:10
linshihhua: 這是因為 struct 只有在 main 函數裡有定義 09/11 23:10
linshihhua: 而離開 main 函數之後就成了未定義的關係嗎 09/11 23:11
Lipraxde: 在大括弧內宣告的話在大括弧外是看不到的 09/11 23:52
steve1012: 應該是要把 struct 定義拿出去而不是把 implementation 09/11 23:53
steve1012: 往後移 09/11 23:53
steve1012: 通常 struct 的宣告都會在外面或是 header 裡面 09/11 23:54