This is just a simple example of a bigger problem. I have the header-file a.h with the following code:
class A {
public:
int a;
A(int b);
}
And the source-file a.cpp with the following code:
#include "a.h"
A::A(int b){
(*this).a = b;
}
Also a main.cpp file which creates an instance of the class:
#include "a.h"
int main () {
A *test = new A(5);
return 0;
}
I'm compiling now on Ubuntu with g++ (5.4) with the following command:
g++ -o main main.cpp
So the problem is now that I get an Error from the Linker which says:
test.cpp:(.text+0x21): Undefined reference to function `A::A(int)'
All the files are in the same destination. So what is the solution here? If I include the a.cpp file in the main.cpp the linker doesn't throw any error. But that should't be the solution.
Hope you guys can help me.