Home > Article > Backend Development > Why Can I Use the Class Name \"Link\" Instead of \"Link\" Within this Class Template?
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
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!