Class template can be either explicitly or implicitly intantiated and the class template is being instantiated implicitly if N3797::14.7.1/1 [temp.inst]
Unless a class template specialization has been explicitly instantiated (14.7.2) or explicitly specialized (14.7.3), the class template specialization is implicitly instantiated when the specialization is referenced in a context that requires a completely-defined object type or when the completeness of the class type affects the semantics of the program.
Let me provide an example when the context is not required the class type to be a completely defined:
#include <iostream>
template<class T>
struct A
{
void foo();
};
template<class T> void A<T>::foo(){ std::cout << "foo" << std::endl; }
A<int>* a;
int main(){ a -> foo(); }
In that example the class template neither explicitly nor implicitly instantiated. So, we actually don't have the definition of the class A<int>
. But despite the fact it works fine. Couldn't you explain that behavior.
A<int>::foo()
, so you need a complete type. Doesn't the quote say that in this case the template is implicitly instantiated? – juanchopanzathis
pointer and an addressable function pointer (also fully typed). – Galik