Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"class template" versus "template class" [duplicate]

Possible Duplicate:
What is the difference between a template class and a class template?

I've seen several C++ gurus rip on people for calling something like

template <typename T>
class SomeClass
{
    //...
};

a template class instead of a class template. (Not a huge rip, mind you, but as an indication that someone isn't an experienced C++ programmer) Yes, the correct word is "class template" -- because it is a template used to generate classes.

But I don't understand why in typical conversation the distinction matters. Nobody listening to/reading what you've written is going to understand what you're talking about to mean anything else.

Is there some specific use of the words "template class" in the standard or otherwise which makes use of those words in that order grossly wrong?

like image 540
Billy ONeal Avatar asked Dec 09 '10 07:12

Billy ONeal


People also ask

What is the difference between class template and template class?

An individual class defines how a group of objects can be constructed, while a class template defines how a group of classes can be generated. Note the distinction between the terms class template and template class: Class template. is a template used to generate template classes.

What is the difference between class and typename in template?

There is no difference between using <typename T> OR <class T> ; i.e. it is a convention used by C++ programmers. I myself prefer <typename T> as it more clearly describes its use; i.e. defining a template with a specific type.

Is class template and function template the same?

The difference is, that the compiler does type checking before template expansion. The idea is simple, source code contains only function/class, but compiled code may contain multiple copies of the same function/class. Function Templates We write a generic function that can be used for different data types.

What is the difference between template typename T and template T?

There is no difference. typename and class are interchangeable in the declaration of a type template parameter.


1 Answers

According to this page :

Note the distinction between the terms class template and template class:

  • Class template is a template used to generate template classes. You cannot declare an object of a class template.
  • Template class is an instance of a class template.

This MSDN page seems to agree on this definition :

Unlike function templates, when instantiating a class template, you must explicitly instantiate the class by giving the arguments for the class templates.

[...]

The compiler generates code for a template class or function when the class or function is instantiated.

like image 77
icecrime Avatar answered Oct 20 '22 19:10

icecrime