Home > Backend Development > C++ > How do Class Names in Class Templates Work Without Template Parameters?

How do Class Names in Class Templates Work Without Template Parameters?

Patricia Arquette
Release: 2024-10-31 11:46:31
Original
441 people have browsed it

How do Class Names in Class Templates Work Without Template Parameters?

Class Names in Class Templates Without Template Parameters

Consider a class template defined as follows:

<code class="cpp">template <typename E>
class Link {
public:
    E element;
    Link* next;  // No typename argument here
};</code>
Copy after login

The code you provided features a public member Link* next without a typename argument. This is known as an "injected class name."

According to [temp.local], when the injected class name is used within the scope of the class, it is equivalent to the class name followed by angle brackets containing the template parameters of the class. In this case, Link effectively becomes Link.

Therefore, the expression Link* next within the Link class is equivalent to Link* next. This convenience feature allows the class to reference itself using its full name without explicitly specifying the template arguments.

The above is the detailed content of How do Class Names in Class Templates Work Without Template Parameters?. 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