Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a common point of confusion for many (including the Generic Programming page on Wikipedia, some C++ tutorials, and other answers on this page). As far as C++ is concerned, <strong>there is no such thing as a "template class," there is only a "class template."</strong> The way to read that phrase is "a template for a class," as opposed to a "function template," which is "a template for a function." <strong>Again: classes do not define templates, templates define classes</strong> (and functions). For example, this is a <em>template</em>, specifically a <em>class template</em>, but <em>it is <strong>not</strong> a class</em>:</p> <pre><code>template&lt;typename T&gt; class MyClassTemplate { ... }; </code></pre> <p>The declaration <code>MyClassTemplate&lt;int&gt;</code> <strong>is a class,</strong> or pedantically, a class based on a template. <em>There are no special properties of a class based on a template vs. a class not based on a template.</em> The special properties are <em>of the template itself</em>.</p> <p>The phrase "template class" means nothing, because the word "template" has no meaning as an adjective when applied to the noun "class" as far as C++ is concerned. It implies the existence of a <em>class</em> that <strong>is</strong> (or defines) a <em>template</em>, which is not a concept that exists in C++.</p> <p>I understand the common confusion, as it is probably based on the fact that the words appear in the order "template class" in the actual language, which is a whole other story.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload