0
votes

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(); }

DEMO

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.

2
You are calling A<int>::foo(), so you need a complete type. Doesn't the quote say that in this case the template is implicitly instantiated?juanchopanza
I suspect calling that function is going to require a properly typed this pointer and an addressable function pointer (also fully typed).Galik

2 Answers

0
votes

[expr.ref]/p2, emphasis mine:

For the second option (arrow) the first expression shall have pointer to complete class type.

Why do you think it's a context that doesn't require a completely-defined object type?

0
votes

See the example at 14.7.1/4 which demonstrates that a -> foo(); is "a context that requires a completely-defined object type".