Hi,

I looked for this information, but couldn't find it anywhere. Is there a difference between a "template class" and a "class template" or are they just two different ways of saying the same thing ?

Thanks a lot.

Dani AI

Generated

Short answer: in standard C++ terminology, a class template is the template itself (the pattern that can generate a family of classes). The phrase template class is informal and ambiguous; most style guides avoid it. If you want to name the concrete thing you get after substituting template arguments, say class template specialization (or just instantiation) instead. See cppreference: Templates and cppreference: Template specialization.

A quick way to keep it straight: if you can point to a line that begins with template<...>, you are talking about a template; if you see something like Name<int> in code, you are looking at a class, produced by that template.

Example you can compile:

template<class T>
struct Box { T value; };   // class template (the pattern)

Box<int> a{};              // instantiation: a class (not a template)
template<> struct Box<void> { }; // full specialization of the class template

Why the wording matters: toolchains and papers use the standard terms when discussing errors, overload resolution, and specialization rules. Using class template vs. class template specialization makes reviews and documentation clearer and avoids confusion with function templates or non-template classes. The standard itself consistently uses these terms and does not define a distinct notion called "template class." See the Templates clause for the formal wording. Templates (C++ Standard draft)

Shout-outs: and captured the essence with the blueprint-vs-instance distinction. If you prefer a strict vocabulary, replace "template class" wherever it appears with either "class template" (the pattern) or "class template specialization" (the concrete class), as that is what compilers and references mean.

Recommended Answers

All 5 Replies

Thanks, but I sort of know what templates are and how to implement them.

I found this information on the ibm website.

which answers my question.

Class Template is the code for generating template classs.

i.e.

template<typename T> foo { } // class template

foo<int> t; // template class

commented: Wasn't worth waiting two YEARS for :( -4

Template class:
A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates.

Class template:
A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It’s jargon for plain classes.

class template is a template that defines a class

template <typename T> class SomeClass {...}; // this is a class template
template <typename T> int some_function(T&) {...} // this is a function template
A template class is a particular kind of class. There are many kinds of classes, and in particular, template classes are those defined using a class template. Contrast:

SomeClass sc; // SomeClass is an ordinary (non-template) class
SomeClass<int> sc; // SomeClass<int> is a template class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.