0

I am trying to compile code with the following structure under codeblocks:

class a : public cppcms::application (has virtual members) {
 public:
   a() : b_inst(this) {}
   ...
   b b_inst;

}

class b {
  public:
    b(a* ptr) : a_ptr(ptr) {}
  private:
    a* a_ptr;
  ...
}

I am trying to put this together with codeblocks/g++ and get the following error message (at the linking stage):

undefined reference to `vtable for b (In function b: ...)

I tried pulling of the same thing with a reference, same result. I tried to change a::b_inst to a pointer and creating an instance of b with new in the constructor (codepart), same result. What is the right way to do this?

By the way, if I do not add the pointer passing on construction, the code works, so i think it is not resolved by the answer here

Community
  • 1
  • 1
ted
  • 4,791
  • 5
  • 38
  • 84
  • Have you got the declaration in the right order in your actual code? As written, this won't even compile. – Kerrek SB Oct 02 '11 at 00:24

1 Answers1

2

undefined reference to `vtable for b (In function b: ...)

That means probably you haven't implemented all of b's virtual methods. gcc emits the vtable when the first one is defined AFAIK.

That means it has nothing to do with the implementation of your constructor.

jpalecek
  • 47,058
  • 7
  • 102
  • 144
  • bedtime for me, thanks alot, this is right, i forgot that i added more than the constructor, and was fixated at the constructor, since the linker pointed there – ted Oct 02 '11 at 00:28