Home  >  Article  >  Backend Development  >  Why Can I Use the Class Name \"Link\" Instead of \"Link\" Within this Class Template?

Why Can I Use the Class Name \"Link\" Instead of \"Link\" Within this Class Template?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-04 06:31:29904browse

Why Can I Use the Class Name

Using Class Name within a Class Template

In the provided code snippet, the public member variable Link* next lacks a template parameter. This is due to a feature known as the "injected class name."

According to the C standard ([temp.local]), within the scope of a class template, the injected class name is equivalent to the template name followed by the template parameters enclosed in <..>. However, when used as a type name, the injected class name refers to the class template itself.

In the case of the Link class template, the injected class name is simply Link. Thus, the line Link* next; is effectively equivalent to Link* next;. Using the injected class name as a shorthand saves the need to explicitly specify the template parameters for the Link pointer.

This feature is convenient within class templates, especially when the template parameter list is extensive. By using the injected class name, the class name can refer to itself without cluttering up the code with excessive template parameters.

The above is the detailed content of Why Can I Use the Class Name \"Link\" Instead of \"Link\" Within this Class Template?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn