Re: Likely causes of Unresolved external symbol in pure virtual function
Phlip wrote:
Dilip wrote:
// file a.cpp
template<typename T>
long derv<T>::somefunc()
{
}
I can't understand why I am getting the linker error -- what is my
mistake?
Each translation unit must (generally) see complete template definitions to
expand them.
That should teach me a lesson -- mucking around with templates without
understanding everything about them.
Move the body of somefunc() from a.cpp to a new file, call it a.inl, and
then #include this into every translation unit that instantiates your
template derv<> with a new type.
would this be appropriate:
================================
// file derv1.inl
template<typename T>
long derv<T>::somefunc()
{
}
================================
================================
// file a.h
class base
{
virtual void somefunc() = 0;
};
template<typename T>
class derv1 : public base
{
virtual void somefunc();
};
// include this at the very bottom of a.h
// likewise include the defn of all classes that might derive from base
#include ".\derv1.inl"
================================
================================
// file a.cpp
#include ".\a.h"
================================
will this work?