passing this from constructor to other constructor yields undefined reference on linking
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
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.
精彩评论