So I'm trying to learn C++ and I've gotten as far as using header files. They really make no sense to me. I've tried many combinations of this but nothing so far has worked:
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; }
What I'm trying to do is pretty simple, but the way the header files work just makes no sense to me at all. Code blocks returns the following on build:
obj\Debug\main.o(.text+0x131)||In function
main':| *voip*\test\main.cpp |6|undefined reference to
testClass::testClass()'| obj\Debug\main.o(.text+0x13c):voip\test\main.cpp|7|undefined reference to `testClass::~testClass()'| ||=== Build finished: 2 errors, 0 warnings ===|
I'd appreciate any help. Or if you have a decent tutorial for it, that would be fine too (most of the tutorials I've googled haven't helped)