I have a template class that inherits from an interface class and therefore has virtual functions
//abstract.h class Abstract { virtual void abc(); Abstract(); } //Abstract.cpp Abstract::Abstract() { //do some init} //concrete.h class Impl { public: void abcImpl(); }; template<typename T> class Concrete : public Abstract, public T { virtual void abc(); }; template<typename T> Concrete<t>::abc() { static_cast<T>(*this).abcImpl(); } //concrete.cpp void Impl::abc() { std::cout << "abc"; }
Used here
//foo.cpp Concrete<Impl> *var1 = new Concrete<Impl>();
At link time, I get an error undefined link to `vtable for Abstract '
In the past, this error indicated that complier could not find a place to place the vtable because there was no cpp file associated with this class. In other words, he puts vtable, where he first finds the first non-virtual definition of any member function. But this is perplexing. 1. Im not sure why he is complaining about Abstract - Abstract actually has cpp 2. Maybe the msg error actually means Concrete? But Concrete cannot be in the cpp file because its templatized. So, how to solve this problem when working with a template class that also has virtual functions?
source share