Re: Likely causes of Unresolved external symbol in pure virtual function
Dilip wrote:
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.
Note I said "generally". That's because I, too, muck around with templates
without understanding everything about them.
Modern compilers are supposed to overcome this limitation, but I don't know
how the new system works, or how many compilers support it. So almost all
projects use their templates the way we are now discussing...
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"
================================
No, because that defeats the purpose of an INL file. Users of a.h might want
to know about the template's declaration without needing to know its
definition. Your system might as well put the template function body inside
a.h. There's nothing special about the .inl extension.
Only include a.inl in every .cpp file that needs it, and this should be
fewer files than need a.h. Generally.
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!