 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
james Guest
|
Posted: Thu Oct 14, 2004 10:02 pm Post subject: Differentiate between a template class and class template |
|
|
Hi guys,
I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
Thanks, james
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Alberto Barbati Guest
|
Posted: Fri Oct 15, 2004 11:30 am Post subject: Re: Differentiate between a template class and class templat |
|
|
james wrote:
| Quote: | Hi guys,
I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
|
According to Vandevoorde/Josuttis (C++ Templates, chapter 7):
<quote>
* [The term /class template/] is a parametrized description of a family
of classes.
* The term /template class/ on the other hand has been used for:
- a synonym for class template
- to refer to classes generated from templates
- to refer to classes with a name that is a template-id
[...] Because of this imprecision, we avoid the term /template class/ in
this book.
</quote>
I cannot but agree with them and it would be good if people stopped
using the term template class once and for all. In support to this view,
the C++ Standard has undergone with TC1 a thorough revision to replace
all uses of the term template class with class template wherever applicable.
Alberto
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Thierry Miceli Guest
|
|
| Back to top |
|
 |
L.Suresh Guest
|
Posted: Fri Oct 15, 2004 4:10 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
class template - Is actually a template that is a class.
Here Foo is a class template.
template <typename T>
class Foo {
};
template class - Is actually a class that is instantiated from a template.
Foo<int> f;
Here f has a type Foo<int>, which is a template class.
You can think think that the second word is qualified with first word.
"class template" : It is a template. template for what? template for class..
"template class" : It is a class. Is it ordinary class? It is a class
generated fro a template.
The same thing exists for funtcion template and template function.
HTH
--lsu
| Quote: | Hi guys,
I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
Thanks, james
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Terje Slettebų Guest
|
Posted: Fri Oct 15, 2004 11:11 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
"Alberto Barbati" <AlbertoBarbati (AT) libero (DOT) it> wrote
| Quote: | james wrote:
Hi guys,
I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
According to Vandevoorde/Josuttis (C++ Templates, chapter 7):
|
<snip>
This reminds me of the "new operator" vs "operator new" confusion, but at
least in that case, they both have a well-defined meaning.
Regards,
Terje
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Antoun Kanawati Guest
|
Posted: Sat Oct 16, 2004 10:16 am Post subject: Re: Differentiate between a template class and class templat |
|
|
L.Suresh wrote:
| Quote: | class template - Is actually a template that is a class.
Here Foo is a class template.
template <typename T
class Foo {
};
template class - Is actually a class that is instantiated from a template.
Foo
Here f has a type Foo<int>, which is a template class.
You can think think that the second word is qualified with first word.
"class template" : It is a template. template for what? template for class..
"template class" : It is a class. Is it ordinary class? It is a class
generated fro a template.
The same thing exists for funtcion template and template function.
|
I like to think of templates and their instantiations. This sort
of terminology is just confusing. It may make sense in a hightly
formalized context to create such distinctions (e.g.: standards
document). However, as soon as such lingo makes it out into the
wild, the meanings get fuzzy. Basically, we're saying that the
phrase 'A B' means that we're referring to a B, which may be quite
obvious if you're Commander Data communicating with the computer.
In any case, these constructs are not robust; the inversion
of sequences, against convention, is an instrument literary,
if you know what I mean. But, seriously, technical terminology
needs to be robust, and resistant to syntactic variatoin.
A lot of technical documentation is done by writing experts,
whose primary concern is with form, not substance.
<digress>
Specialization is a highly prized quality in current culture.
While this leads to great advances in various domains, it also
creates vast chasms between them. We often fail to educate
our engineers and scientists in communication and language
skills. We also fail to educate our 'business' specialists
in the domains that they're going to do business in, etc...
</digress>
So, a robust technical term is one that dictates its correct
form, even in the absence of substance. More reasonably:
if you have a set of transformations representing common
errors, and you apply them to the technical term, ideally
all of them should be detectable as errors on the basis
of form alone. Practically, you don't want the erroneous
forms to express a different concept that fits equally
well where your intended concept is supposed to be; i.e.:
even if the syntax and grammar were correct, you'd expect
that in the general context of the technical domain, and
without prior knowledge of the intended meaning, a reader
will be able to detect that something is wrong; ideally,
this reader should also be able to deduce the original
meaning.
For example, if a Scheme programmer looks at sentence where
'class template' is used erroneously instead of 'template
class', can this programmer detect, reliably and without
prior knowledge of the intended meaning, that the sentence
is wrong?
--
A. Kanawati
[email]NO.antounk.SPAM (AT) comcast (DOT) net[/email]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Tom Widmer Guest
|
Posted: Sat Oct 16, 2004 4:58 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
On Thu, 14 Oct 2004 22:02:39 +0000 (UTC), [email]james_merch (AT) hotmail (DOT) com[/email]
(james) wrote:
| Quote: |
Hi guys,
I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
|
A template class is generally an informal name for what the C++
standard calls a class template. IOW, they are the same thing.
However, "template class" is misleading, since it leads to the
impression that a class template is actually a class, whereas in fact
it is a template for making classes. However, since "template class"
isn't a formally defined term, they might be using it to refer to a
class template specialization, but I don't think that's the most
common usage.
Although the standard doesn't use "template class" at all, it does use
the phrase "non-template class", but, to be honest, I think that's not
really a correct usage - by definition, a class isn't a class template
in any case, so "non-template class" == "class".
Tom
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Sat Oct 16, 2004 4:58 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
In article <e2ef22db.0410131551.1c43209e (AT) posting (DOT) google.com>, james
<james_merch (AT) hotmail (DOT) com> writes
| Quote: | Hi guys,
I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
|
A template class is a template from which class definitions can be
generated (just as a function template is a template from which
functions can be generated.)
{Moderator's note: I'm pretty sure Francis meant the next sentence
to begin with "A class template..." -mod/dk}
A template class is whatever you make it mean. Personally I do not use
the term, but if I did it would be to refer to a class that had been
generated from a template.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Sumit Rajan Guest
|
Posted: Sat Oct 16, 2004 4:58 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
james wrote:
| Quote: | Hi guys,
I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
|
In case of you have access to a copy of "C++ Templates: The Complete
Guide" you may like to look up Section 7.1("Class Template" or "Template
Class"?).
--
Sumit Rajan <sumit DOT rajan AT gmail DOT com>
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Sharad Kala Guest
|
Posted: Sat Oct 16, 2004 4:58 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
"james" <james_merch (AT) hotmail (DOT) com> wrote in message
| Quote: | I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
|
Is there anything like "template class" ? AFAIK, no. The correct term to be
used is "class template". But the irony is that while writing a class
template you write "template class"
template <class MyType>
:-)
Sharad
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Graeme Prentice Guest
|
Posted: Sat Oct 16, 2004 4:58 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
On Thu, 14 Oct 2004 22:02:39 +0000 (UTC), james wrote:
| Quote: |
Hi guys,
I had an interview a few days ago and the interviewer
asked me this C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
|
"class template" refers to the definition of a class that is a template.
A class template is a template - it's a "pattern"
e.g.
template <typename T> class abc { T x; };
abc is the name of a template - a class template. It is not a class.
abc<int> is the name of a class, it is not a template but is a class
generated from a template - a class generated from a template is
sometimes referred to as a template class. A class generated from a
template has an official name of "class template specialization".
abc<int> is also called a template-id i.e. a template-id is the name of
a template followed by a list of one or more template arguments between
the angle brackets. A template-id identifies a specialization of a
template.
In my opinion this is a semi trick question. If you search on
groups.google.com you'll get 12,600 hits for "class template" and 72,800
for "template class" - however the "template class" search picks up
template
template, you get equal numbers and you can soon see that the terms are
used interchangeably.
The 2003 revision of the C++ standard (TC1) uses the term "class
template" 475 times and "template class" about 4 or 5 times.
The 1998 C++ standard uses "template class" approx 215 times and "class
template" 255 times.
i.e. the 2003 revision of the C++ standard changed many instances of
"template class" to "class template". Similarly some instances
"template function" were changed to "function template".
If you have a copy of C++ templates by Vandevoord and Josuttis, they
point out that "template class" is used to mean at least three different
things
- as a synonym for class template
- to refer to classes generated from templates
- to refer to classes with a name that is a template-id
The book says it avoids the term "template class" because of the
multiple meanings - however in every day usage, it's usually clear
what is meant when "template class" is used.
In the C++ standard, the correct terminology can matter quite a lot
(especially regarding functions) but in every day usage the meaning of
"template class" is usually clear from the context.
Graeme
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Keith H Duggar Guest
|
Posted: Sun Oct 17, 2004 1:37 am Post subject: Re: Differentiate between a template class and class templat |
|
|
| Quote: | I like to think of templates and their instantiations. This sort of
terminology is just confusing.
|
As evidenced by the OP and the info Alberto provided.
| Quote: | It may make sense in a hightly
formalized context to create such distinctions (e.g.: standards
document).
|
You are right it does make sense to create distintions; but (as you
point out later) not using confusing terminology.
| Quote: | digress
Specialization is a highly prized quality in current culture.
While this leads to great advances in various domains, it also creates
vast chasms between them. We often fail to educate our engineers and
scientists in communication and language skills. We also fail to
educate our 'business' specialists in the domains that they're going
to do business in, etc...
/digress
|
That is certainly true.
| Quote: | For example, if a Scheme programmer looks at sentence where 'class
template' is used erroneously instead of 'template class', can this
programmer detect, reliably and without prior knowledge of the
intended meaning, that the sentence is wrong?
|
As evidenced by the OP often even C++ programmers can't detect the
error. So often writers forget that the chief purpose of human language
is to COMMUNICATE with fellow humans. Not to create some form of
*machine* language that is difficult to understand.
<digress>
For similar reasons, in another thread, I once objected to the use of
cryptic, trendy acronyms like IMHO, IIRC, FWIW, etc. rather than simply
writing (or better eliminating) the useless phrase. This notion received
very little support.
Many seemed habitually attached to their specialized internet language.
Then, just a few days ago, there was a prime time news report about how
children are using multitudes of new cryptic acronyms to hide the
meaning of their conversations from parents often leading them into harm
(like to Michael or Pee Wee's house).
</digress>
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Mon Oct 18, 2004 1:40 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
Sharad Kala <no_spam.sharadk_ind (AT) yahoo (DOT) com> writes:
| Quote: | "james" <james_merch (AT) hotmail (DOT) com> wrote in message
I had an interview a few days ago and the interviewer asked me this
C++ question:
"Differentiate between a template class and class template?"
Can anyone explain me the differences?
Is there anything like "template class" ? AFAIK, no. The correct term
to be used is "class template".
|
That term was used in the earlier drafts of the C++ standard text. It
has been changed (I think) between CD2 and the final draft. It used to
mean a class generated from a class template. It can lead to
interesting sentences :-)
--
Gabriel Dos Reis
[email]gdr (AT) cs (DOT) tamu.edu[/email]
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Graeme Prentice Guest
|
Posted: Mon Oct 18, 2004 1:40 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
On Sat, 16 Oct 2004 16:58:03 +0000 (UTC), Graeme Prentice wrote:
| Quote: |
If you have a copy of C++ templates by Vandevoord and Josuttis, they
point out that "template class" is used to mean at least three
different things
- as a synonym for class template
- to refer to classes generated from templates
- to refer to classes with a name that is a template-id
The book says it avoids the term "template class" because of the
multiple meanings - however in every day usage, it's usually clear
what is meant when "template class" is used.
|
oops, I didn't quite mean that - the book doesn't say both of those
things in the last sentence above. The book says it avoids the term
"template class" because of its imprecision. The second part of the
above is my opinion.
Graeme
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Terje Slettebų Guest
|
Posted: Mon Oct 18, 2004 4:31 pm Post subject: Re: Differentiate between a template class and class templat |
|
|
"Keith H Duggar" <duggar (AT) alum (DOT) mit.edu> wrote
| Quote: | I like to think of templates and their instantiations. This sort of
terminology is just confusing.
digress
For similar reasons, in another thread, I once objected to the use of
cryptic, trendy acronyms like IMHO, IIRC, FWIW, etc. rather than simply
writing (or better eliminating) the useless phrase. This notion received
very little support.
Many seemed habitually attached to their specialized internet language.
Then, just a few days ago, there was a prime time news report about how
children are using multitudes of new cryptic acronyms to hide the
meaning of their conversations from parents often leading them into harm
(like to Michael or Pee Wee's house).
/digress
|
Children using a special language/secret codes/slang is nothing new. It
lets them have something that is "theirs"; their own way of expression.
As for acronyms and terminology, as has been pointed out in previous
discussions about that, those are very common in virtually every field: They
enable concise communication and avoiding ambiguity. Think about it: Would
you rather talk about Complementary Metal-Oxide Semiconductor Random Access
Memory, or CMOS RAM?
Similarly, online communication has developed its own "language" of common
terminology and abbreviations.
This post by James Dennett, from the earlier discussion, I think gives a
very good account of the points:
http://www.google.com/groups?selm=D0FKc.22362%249I.13304%40okepread02
Regards,
Terje
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|