I'm pretty new to C++ and I keep getting undefined reference errors to constructors although they are defined and included. I know this is a pretty common error and there's many questions about this, but each one seems a bit different from mine and I am unable to resolve my problems.
Basically I want a class B to have an instance variable of class A, which is a virtual class with a "real" subclass ASub. Also, the files for class A are in ~/level1/ and the files for class B are in ~/level1/level2/.
I keep getting the following errors:
error: undefined reference to 'mynamespace::A::A()'
error: undefined reference to 'mynamespace::A::~A()'
a.h looks like this:
#ifndef A_H__
#define A_H__
namespace mynamespace {
class A {
 public:
  A();
  virtual ~A();
};
class ASub : public A {
 public:
  ASub();
  ~ASub();
};
} // namespace mynamespace
#endif  // A_H__
a.cc looks like this:
#include "level1/a.h"
namespace mynamespace {
A::A() {}
A::~A() {}
ASub::ASub() {}
ASub::~ASub() {}
};  // namespace mynamespace
b.h looks like this:
#ifndef B_H__
#define B_H__
#include "level1/a.h"
namespace mynamespace {
class B {
 public:
  B();
  ~B();
  void SetA(A a);
 private:
  A a_;
};
} // namespace mynamespace
#endif  // B_H__
And finally b.cc looks like this:
#include "level1/level2/b.h"
#include "level1/a.h"
namespace mynamespace {
B::B() {}
B::~B() {}
void B::SetA(A a) {
  a_ = a;
}
};  // namespace mynamespace
 
    