tags:

views:

60

answers:

3

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?

A: 

It is implementation defined.

But usually when a template class is instantiated all member for the new class type are generated.

Martin York
+3  A: 

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.

Johannes Schaub - litb
+1  A: 

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.

Kirill V. Lyadvinsky
He wants to know whether the function is instantiated or not. Not where the instantiation is put to.
Johannes Schaub - litb