看板 LinuxDev 關於我們 聯絡資訊
為了練習OOP 我寫了一個小程式 共分成三個部份 如下: =================part I: myclass.h=================== #ifndef MYCLASS_H #define MYCLASS_H class myclass{ public: myclass(int = 0); void setvalue(int); int getvalue(); private: int value; }; #endif ================part II: myfun.cpp===================== #include "myclass.h" myclass::myclass(int arg) { setvalue(0); } void myclass::setvalue(int arg) { value = arg; } int myclass::getvalue() { return value; } ================part III: test.cpp===================== #include <iostream> using namespace std; int main() { myclass Obj; cout << "value = " << Obj.getvalue() << endl; Obj.setvalue(10); cout << "value = " << Obj.getvalue() << endl; return 0; } 問題是 編譯時如果輸入g++ -o test.o test.cpp 則編譯器不知道還有myfun.cpp 那該怎麼作才能一次編譯出上面那三個檔案呢? 小弟剛用linux不久 還請各位大大不另指教 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.240.190.163 ※ 編輯: amu1661024 來自: 123.240.190.163 (12/22 17:04)
dozer:g++ myfun.cpp test.cpp -o test 12/22 17:11
dozer:test.cpp少了include "myclass.h" 12/22 17:12
CriLit:g++ -c 每個 .cpp, 最後再 -o 全部 12/22 17:12
dozer:呃, #include ^^;;; 12/22 17:12
amu1661024:3Q^^ 12/22 17:16