I know that the normal member function of an template class will be instantiated whenever it is used for the first time. But this cannot be done for the virtual member function as it can be accessed through base class pointer. This means that virtual member functions will be instantiated as soon as the tmeplate class is instantiated? If not when?
It is implementation defined.
But usually when a template class is instantiated all member for the new class type are generated.
14.7.1/9
in C++03:
An implementation shall not implicitly instantiate a function template, a member template, a non-virtual member function, a member class or a static data member of a class template that does not require instantiation. It is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated.
According to the C++ Standard 14.6.4.1/4:
If a virtual function is implicitly instantiated, its point of instantiation is immediately following the point of instantiation of its enclosing class template specialization.