成员class实例化

Member class instantiation

N4296::14.7.1/1 [temp.inst] 告诉我们以下内容:

The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions, [...], member classes, [...]

这条规则是关于什么的?让我举个例子:

template<class T>
class A
{
public:
    template<class W> class Y; //1, declaration
    template<class V> class U{ V v; };  //2, definition
};

A<int> a; //3, implicit instantiation
int main(){ }

//3 处的隐式实例化会导致 //2 处和 //1 处的隐式实例化吗?如果是这样,使用什么模板参数来实例化这些成员 类?

与 "outer" 模板相比,这些成员模板没有什么特别之处。编译器将它们作为声明读取,这样它就知道存在名称 A<T>::Y<W>A<T>::U<V>,这与为 class A:[=14= 声明模板时非常相似]

template <typename T>
class A {
     int a;
};

它也只声明了 class A<T> 的存在,但没有实例化它。

实例化被推迟到实际使用(或显式实例化)模板化类型时,这同样适用于成员模板。