//Double.h file
#ifndef Double_h
#define Double_h
int add(int x,int y);
#endif
//Double.cpp file
int add(int x,int y)
{
return x + y;
}
//main.cpp file
#include <iostream>
#include "Double.h"
using namespace std;
int main()
{
cout << add(7,8)<<endl;
return 0;
}
它應該是一個簡單的7 + 8程序,我使用的是C++的Codeblocks。它一直說add wasn't declared in this scope
。並且當我DID在using namespace std;
之後在main.cpp文件中聲明int add (int x,int y)
時,它表示"undefined reference for add(int,int)
。我不明白這一點,我真的認爲它會起作用。有人能指出這個錯誤嗎?獲取關於未定義參考的錯誤,儘管它被定義爲
我應該在#include「Double.h」中包含Double.h ???? – user711602 2011-04-17 03:37:52
它仍然沒有工作,他們都在同一個文件夾中......這真的很奇怪。 – user711602 2011-04-17 03:39:34
並等待你的意思是通過編譯main.cpp和double.cpp在一起??建立他們兩個正確???我試過了,它一直在說一些「未定義的引用Winmain @ 16」錯誤 – user711602 2011-04-17 03:40:30