[問題] 呼叫別的.cpp檔內的函數

看板C_and_CPP (C/C++)作者 (幻)時間16年前 (2009/08/29 04:50), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串1/1
我有一個寫好的類別 在 CExpense.h 及 CExpense.cpp內 如 class CExpense : public CBase { public : void ConstructL(); ~CExpense(); .... } 如果我要在另一個.cpp檔內 呼叫這個 ConstructL() 如 CExpense.ConstructL(); compile時會發生錯誤: expected primary-expression before '->' token 用 CExpense::ConstructL(); 也會錯誤: cannot call member function `void CExpenseDb::ConstructL()' without object 請問哪裡寫錯了 還是遺漏了什麼 thakns~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.204.20.126

08/29 04:57, , 1F
你完全使用錯誤了
08/29 04:57, 1F

08/29 04:58, , 2F
你要用 要用object去呼叫 CExpense obj;obj.ConstructL();
08/29 04:58, 2F

08/29 04:58, , 3F
你要用CExpense::ConstructL();你要宣告成static void Con...
08/29 04:58, 3F

08/29 04:59, , 4F
你錯誤訊息也寫得很明確了
08/29 04:59, 4F
文章代碼(AID): #1Ac4CUWf (C_and_CPP)
文章代碼(AID): #1Ac4CUWf (C_and_CPP)