Home > Backend Development > C++ > body text

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

Patricia Arquette
Release: 2024-11-04 06:31:29
Original
903 people have browsed it

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!