另一個文件我不能實例化一個類這項工作C++不能從main.cpp中
Addr.h
#ifndef ADDR_H
#define ADDR_H
class Foo{
public:
Foo(); // function called the default constructor
Foo(int a, int b); // function called the overloaded constructor
int Manipulate(int g, int h);
private:
int x;
int y;
};
#endif
Addr.cpp
#include "addr.h"
Foo::Foo(){
x = 5;
y = 10;
}
Foo::Foo(int a, int b){
x = a;
y = b;
}
int Foo::Manipulate(int g, int h){
return x = h + g*x;
}
的main.cpp
#include "addr.cpp"
int main(){
Foo myTest = Foo(20, 45);
while(1){}
return 0;
}
我在做什麼錯?我得到這些鏈接器錯誤:
錯誤LNK2005:「public:int __thiscall Foo :: Manipulate(int,int)」(?Manipulate @ Foo @@ QAEHHH @ Z)已經在addr.obj中定義了c:\ Users \基本文件\ visual studio 2010 \項目\控制檯測試\控制檯測試\ main.obj
錯誤LNK2005:「public:__thiscall Foo :: Foo(int,int)」(?? 0Foo @@ QAE @ HH @ Z)已在addr.obj中定義c:\ Users \ christian \ documents \ visual studio 2010 \ Projects \ Console Test \ Console Test \ main.obj
error LNK2005:「public:__thiscall Foo :: Foo(void) 「(?? 0Foo @@ QAE @ XZ)已經在addr.obj中定義了c:\ Users \ christian \ documents \ visual studio 2010 \ Projects \ Console Test \ Console Test \ main.obj
錯誤LNK1169:一個或多個多重定義符號找到C:\ Users \用戶基督教\文檔\ Visual Studio 2010的\項目\控制檯測試\發佈\控制檯將Test.exe
我希望任何形式的幫助! !
謝謝^^,我沒有注意到:d – Christian 2011-05-08 18:40:50