[問題] 關使用於g++編譯時的小問題

看板LinuxDev作者 (人生遊戲 戲遊人生)時間16年前 (2009/12/22 17:03), 編輯推噓4(401)
留言5則, 3人參與, 最新討論串1/1
為了練習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)

12/22 17:11, , 1F
g++ myfun.cpp test.cpp -o test
12/22 17:11, 1F

12/22 17:12, , 2F
test.cpp少了include "myclass.h"
12/22 17:12, 2F

12/22 17:12, , 3F
g++ -c 每個 .cpp, 最後再 -o 全部
12/22 17:12, 3F

12/22 17:12, , 4F
呃, #include ^^;;;
12/22 17:12, 4F

12/22 17:16, , 5F
3Q^^
12/22 17:16, 5F
文章代碼(AID): #1BC8jmpH (LinuxDev)
文章代碼(AID): #1BC8jmpH (LinuxDev)