[問題] invalid use of incomplete type

看板C_and_CPP (C/C++)作者 (早起精神好)時間13年前 (2013/03/20 23:20), 編輯推噓1(102)
留言3則, 1人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux 問題(Question): 請問不同class之間要使用另一個class的function 其中 String a::test(int istrue) { StringAccum sa; if (istrue == 1) { sa << "yes" << "\n";} else { sa << "no " << "\n";} return sa.take_string(); } 另一個class b要使用a的這個function String b::print_links() { // LinkTableMulti _link_table; StringAccum sa; sa << _a->test(1); return sa.take_string(); } hh檔裡面 加了 class a *_a; 但是我會編譯不過 產生 error: invalid use of incomplete type ‘struct a’ error: forward declaration of ‘struct a' 不太了解這個錯誤的原因是為什麼? 請提示一下 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.144.129

03/20 23:47, , 1F
使用type a卻沒有宣告a,compiler都提示關鍵字了...
03/20 23:47, 1F

03/20 23:47, , 2F
b的header裡面 你要forward declaration class A
03/20 23:47, 2F

03/20 23:47, , 3F
或者引入 A 的定義header
03/20 23:47, 3F
我有include a 進header檔阿 找到問題了 沒有ELEMENT_REQUIRES(a) 謝謝樓上解答 ※ 編輯: tanker 來自: 140.113.144.129 (03/21 17:51)
文章代碼(AID): #1HITEeIR (C_and_CPP)
文章代碼(AID): #1HITEeIR (C_and_CPP)