[問題] Multiple Definition

看板EE_DSnP作者 (馬克羅貝斯小徑)時間15年前 (2009/01/18 20:57), 編輯推噓5(501)
留言6則, 5人參與, 最新討論串1/1
這是我的.h(未完成): #ifndef HEADERS_H #define HEADERS_H #include <cstdlib> #include <iostream> #include <iomanip> #include <ctime> #include <fstream> #include <string> #include <conio.h> #define DELAY 20000 using namespace std; void time_output(); class Input { public: static int _count; static void SetCount() { _count++; } char GetInputArticle(int i){return _InputArticle[i];} string GetFile(); private: string _InputArticle; }; #endif GetFile.cpp: #include "headers.h" string Input::GetFile(){ ifstream ifs ("test.txt",ios::in); if(!"test.txt"){ cerr<<"No file:\"text.txt\""<<endl; system ("pause"); } _InputArticle=""; ifs>>_InputArticle; return _InputArticle; } 可是compile會跑出這個訊息兩次 multiple definition of `Input::GetFile()' first defined here 我google了一下,說只要不把function的內容寫在.h檔裡就可以解決 可是我另外開一個GetFile.cpp後,反而多出一次一樣的錯誤訊息 有誰知道怎麼解決嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.68.74.226

01/18 21:18, , 1F
這真是太神奇了,我把程式碼貼到另一份新的檔案就好了
01/18 21:18, 1F

01/18 22:02, , 2F
這... 不知道 DevC++ 如何 make clean...
01/18 22:02, 2F

01/19 03:00, , 3F
好像只有「重新編譯全部檔案」這個按鈕的功能比較接近XD
01/19 03:00, 3F

01/19 08:53, , 4F
是的,其他的都只會編譯有修改的檔案(cpp)而已
01/19 08:53, 4F

01/19 11:07, , 5F
make clean 是什麼?
01/19 11:07, 5F

01/19 21:16, , 6F
就是三樓說的意思
01/19 21:16, 6F
文章代碼(AID): #19SoSaFb (EE_DSnP)