How to read the template partial specialization?

前端 未结 4 1494
不思量自难忘°
不思量自难忘° 2021-01-20 06:16

Suppose the following declaration:

template  struct MyTemplate;

The following definition of the partial specialization se

4条回答
  •  青春惊慌失措
    2021-01-20 06:35

    You have this line:

    MyTemplate c;
    

    Your confusion seems to come from assuming that the int * in < > somehow corresponds to the T in template . It does not. In a partial specialisation (actually in every template declaration), the template parameter names are simply "free variable" (or perhaps "placeholder") names. The template arguments (int * in your case) don't directly correspond to these, they correspond to what is (or would be) in the < > following the template name.

    This means that the part of the instantiation maps to the part of the partial specialisation. T is just a name introduced by the template prefix. In the entire process, the T is int.

提交回复
热议问题