[問題] 請問全域struct extern問題,哪邊寫錯了?

看板C_and_CPP (C/C++)作者 (鋼鐵人史塔克)時間13年前 (2012/12/25 11:50), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
請教一個簡單的問題 我想寫一個 struct,利用這個struct作一個陣列,寫成全域使用 // test.h 宣告 struct student { int age; }; extern student class[10]; // 想要給其它include test.h 的**.C叫用 //test.c 中賦值給第一個學生 class[0].age=13; 可是compile錯誤 顯示 error LNK2001: 無法解析的外部符號 請問我要怎樣寫成全域的,並且這個struct是一個陣列 HELP~~~ Thanks -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.241.70

12/25 12:01, , 1F
你在隨便一個.c 寫上student class[10]; 就可了
12/25 12:01, 1F

12/25 12:01, , 2F
你可以搜extern 關鍵字 版上有一些意義教學
12/25 12:01, 2F

12/25 12:17, , 3F
可以了...謝謝
12/25 12:17, 3F
文章代碼(AID): #1GsI9sia (C_and_CPP)
文章代碼(AID): #1GsI9sia (C_and_CPP)