How to read the template partial specialization?

前端 未结 4 1496
不思量自难忘°
不思量自难忘° 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:27

    There is no contradiction. T should be read as T, T* is T*.

    template struct MyTemplate {};

    "In the first part of this line (i.e. template ), T is int *."

    No - in template T is int, in struct MyTemplate {}; T is also int.

    "Note that when a partial specialization is used, a template parameter is deduced from the specialization pattern; the template parameter is not simply the actual template argument. In particular, for Vector, T is Shape and not Shape*." (Stroustrup C++, 4th ed, 25.3, p. 732.)

提交回复
热议问题