C++ and Header file help required

  • Thread starter Thread starter k++
  • Start date Start date

k++

k++

Associate
Joined
5 Oct 2004
Posts
585
Location
London
I have a main c++ file, for example called a.cpp

I also have two other files, b.h and b.cpp and a.cpp includes b.h

a.cpp
Code:
#include "b.h"
using namespace std;

int main() {
  TestClass test (100);
  return 0;
}

b.h
Code:
class TestClass {
public:
  int value;
  TestClass();
  TestClass(int new_value);
}

b.cpp
Code:
#include "b.h"

TestClass::TestClass() {
  value = 0;
}

TestClass::TestClass(int new_value) {
  value = new_value;
}

Please could someone explain why when I compile a.cpp I get the error "Undefined Symbols"

referring to

Code:
TestClass(int)

If I try to do exactly the same in the b.cpp I don't have any problems, why is a.cpp unable to use the class from b.h which is defined in b.cpp?

regards
 
Last edited:
Wow I'm dumb, my makefile was causing the problem

This thread can now be deleted :)
 
Is it because you have #includes instead of #include?
Just guessing as I haven't done any C for 15+ years and can't remember for toffee!!

This isn't my actual code, I just typed it into the message box as an example. I seem to have fixed my program, for now :p

Thanks for the quick response
 
Back
Top Bottom