當我在eclipse中編譯C++項目時,它向我顯示錯誤,指出IO.cpp中的所有函數都已定義。在Eclipse中構建項目時出錯
這是我的代碼:
文件:IO.cpp
#include <string>
#include <iostream>
using namespace std;
void print(string line) {
cout << line;
}
void println(string line) {
cout << line << endl;
}
void printError(string message, string error, string file) {
cout << "An error occurred!" << endl;
cout << "Message: "+ message << endl;
cout << "Error: "+ error << endl;
if(file != "") {
cout << "File/Method: "+ file << endl;
}
}
文件:main.cpp中
#include <string>
#include <iostream>
#include "IO.cpp"
using namespace std;
int main()
{
println("Hello world!");
}
規則1:不要在其他文件中包含'.cpp'文件。 – CoryKramer 2014-08-30 17:29:15