473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

class vs. typename

What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?

--
Best regards,
Alex.

PS. To email me, remove "loeschedies" from the email address given.
Jul 22 '05 #1
10 5369

"Alexander Malkis" <al*****************@stone.cs.uni-sb.de> wrote in message
news:c4**********@hades.rz.uni-saarland.de...
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?


None at all.

I think typename was introduced because not all template parameters are
classes.

john
Jul 22 '05 #2

"Alexander Malkis" <al*****************@stone.cs.uni-sb.de> wrote in message
news:c4**********@hades.rz.uni-saarland.de...
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?


None at all.

I think typename was introduced because not all template parameters are
classes.

john
Jul 22 '05 #3
John Harrison wrote:

"Alexander Malkis" <al*****************@stone.cs.uni-sb.de> wrote in
message news:c4**********@hades.rz.uni-saarland.de...
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?


None at all.

I think typename was introduced because not all template parameters are
classes.

john

I believe we need to restrict the discussion to template parameters in order
for that to hold. This is from the C++ Standard:

"There is no semantic difference between class and typename in a
template-parameter."

Just being pedantic.
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #4
John Harrison wrote:

"Alexander Malkis" <al*****************@stone.cs.uni-sb.de> wrote in
message news:c4**********@hades.rz.uni-saarland.de...
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?


None at all.

I think typename was introduced because not all template parameters are
classes.

john

I believe we need to restrict the discussion to template parameters in order
for that to hold. This is from the C++ Standard:

"There is no semantic difference between class and typename in a
template-parameter."

Just being pedantic.
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #5
On Tue, 6 Apr 2004 20:45:09 +0100, "John Harrison"
<jo*************@hotmail.com> wrote:

"Alexander Malkis" <al*****************@stone.cs.uni-sb.de> wrote in message
news:c4**********@hades.rz.uni-saarland.de...
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?

None at all.

I think typename was introduced because not all template parameters are
classes.

Actually it was introduced in order to inform the compiler that a name
dependent upon a template parameter is a type; Standard C++ assumes that it
is not in that context unless the typename keyword is used. However, many
existing implementations allow the "typename" to be omitted in that
context, some [like gcc] at least warning you about the assumptions being
made.

I think they chose to allow "typename" instead of "class" for template
parameters after the fact, simply as a way to document the nature of the
type parameters expected. This is one of stylistic issues for which the
"pendulum" still seems to be swinging...
-leor

john


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #6
On Tue, 6 Apr 2004 20:45:09 +0100, "John Harrison"
<jo*************@hotmail.com> wrote:

"Alexander Malkis" <al*****************@stone.cs.uni-sb.de> wrote in message
news:c4**********@hades.rz.uni-saarland.de...
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?

None at all.

I think typename was introduced because not all template parameters are
classes.

Actually it was introduced in order to inform the compiler that a name
dependent upon a template parameter is a type; Standard C++ assumes that it
is not in that context unless the typename keyword is used. However, many
existing implementations allow the "typename" to be omitted in that
context, some [like gcc] at least warning you about the assumptions being
made.

I think they chose to allow "typename" instead of "class" for template
parameters after the fact, simply as a way to document the nature of the
type parameters expected. This is one of stylistic issues for which the
"pendulum" still seems to be swinging...
-leor

john


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #7
Alexander Malkis wrote:
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?


"class" has less characters in it than "typename", so saves more trees.

:-)
--
http://www.it-is-truth.org/
Jul 22 '05 #8
Alexander Malkis wrote:
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?


"class" has less characters in it than "typename", so saves more trees.

:-)
--
http://www.it-is-truth.org/
Jul 22 '05 #9
Alexander Malkis wrote:
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?

I don't know if anybody mentioned this, I just learned it. It is discussed
in TC++PL(SE) Appendix C.13.5. Stroustrup explains it as a way of
disambiguating statements in template declarations. For example
template<class C> void h(C& v)
{
typename C::iterator i = v.begin();
}

--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #10
NPC

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:Mp********************@speakeasy.net...
Alexander Malkis wrote:
What's the semantical/syntactical difference between two keywords
"class" and "typename" (apart from different spelling)?
I don't know if anybody mentioned this, I just learned it. It is

discussed in TC++PL(SE) Appendix C.13.5. Stroustrup explains it as a way of
disambiguating statements in template declarations. For example
template<class C> void h(C& v)
{
typename C::iterator i = v.begin();
}

--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org

Sometimes compilers need some guidance. Typename is a way of telling the
compiler that C::iterator is a C++ Type (as opposed to a C++ function call,
for example).
You will only see typename used in contexts related to programs using
templates.
As far as how/when to use typename : use it when inside of a templated
class/function and refering to a typedef belonging to the templated
parameter. For example, C in you code above is a templated parameter.
iterator is a typedef defined in C. Therefore, you must use the typename
keyword when declaring an object of that type (or if re-typedef'ing (in C):
typedef typename C::iterator IteratorType).

NPC
Jul 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jon Slaughter | last post by:
I've managed to put together a template class that basicaly creates a recursive tree that lets you easily specify the "base" class of that tree and and ending notes and lets you stop the recursive...
5
by: Axter | last post by:
I'm fine tuning a scope_handle class that takes a policy class as the second template. http://code.axter.com/scope_handle.h Please see above link for full understanding of the problem. One...
11
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
12
by: mast2as | last post by:
Hi everyone I am working on some code that uses colors. Until recently this code used colors represented a tree floats (RGB format) but recently changed so colors are now defined as spectrum....
25
by: David Sanders | last post by:
Hi, As part of a simulation program, I have several different model classes, ModelAA, ModelBB, etc., which are all derived from the class BasicModel by inheritance. model to use, for example...
15
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and...
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
6
by: Dan Smithers | last post by:
I want to write my own class derived from the ostream class. I have been getting errors with my templates: First, I get an error writing a nested template. If I leave the function definition...
6
by: Peng Yu | last post by:
Hi, I want B has all the constructors that A has. Obviously, the code below would not work. I could define a corresponding B's constructor for each A's constructor. But if A has many...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.