Re: Likely causes of Unresolved external symbol in pure virtual function
Victor Bazarov wrote:
Dilip wrote:
I can't understand why I am getting the linker error -- what is my
mistake?
Isn't this in the FAQ? See section on templates.
Victor
Thanks for the pointer. I looked up the FAQ and read this (and others
too):
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.15
While I understood the motivation, Philp's idea seems to be easier
because I am getting confused with 2 issues here.
#1) Cline's faq basically asks you to do a empty instantiation in the
..cpp file. So if my main code creates several different instances of
the derived template class with different template parameters, should I
include a empty instantiation for every such parameter?
#2) I had a situation like this that I couldn't immediately figure out
what to do:
// file a.h
class base
{
virtual void dosomething() = 0;
// I need the type parameter passed to derv for _only_
// this method in base
template<typename T>
void somefunc();
};
template<typename T>
class derv1 : public base
{
virtual void dosomething();
};
// derv1.cpp
template<typename T>
void derv<T>::dosomething()
{
somefunc<T>();
}
// file main.cpp
base* pBase = new derv1<int>();
pBase->dosomething();
how should I now define the empty instantiation for somefunc()?
is it:
template class base::somefunc<???>;
2 observations:
1. The above does not even compile (obviously the real code doesnt have
???)
2. the type parameter is dependant on the derived classes -- each of
them pass in their own stuff. How do I forward declare it?