因此,我正在嘗試學習C++,並且儘可能使用頭文件。他們真的對我毫無意義。我試過很多這樣的組合,但沒有迄今已工作:嘗試編譯使用Code :: Blocks的第二個模塊時出現C++鏈接器錯誤
Main.cpp的:
#include "test.h"
int main() {
testClass Player1;
return 0;
}
test.h:
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
class testClass {
private:
int health;
public:
testClass();
~testClass();
int getHealth();
void setHealth(int inH);
};
#endif // TEST_H_INCLUDED
TEST.CPP:
#include "test.h"
testClass::testClass() { health = 100; }
testClass::~testClass() {}
int testClass::getHealth() { return(health); }
void testClass::setHealth(int inH) { health = inH; }
我想要做的事很簡單,但頭文件的工作方式對我來說根本沒有意義。代碼塊返回上構建如下:
OBJ \調試\ main.o(+的.text 0x131)||在功能
main':| *voip*\test\main.cpp |6|undefined reference to
的TestClass :: TestClass的()「| ()。testClass()'testClass()'的未定義引用。 || ===構建完成:2個錯誤,0個警告=== |
我很感激任何幫助。或者如果你有一個體面的教程,這也可以(我已經使用的大多數教程都沒有幫助)
謝謝你,解決了它。感謝您的提示。 – Karl 2010-06-08 21:00:09