ក្រុម រូបភាព ថតឯកសារ វ៉ែប
Recently Visited Groups | Help | Sign in
Google Groups Home
template declaration
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rahul  
View profile  
 More options Jan 13 2008, 7:11 pm
Newsgroups: comp.lang.c++
From: Rahul <sam_...@yahoo.co.in>
Date: Sun, 13 Jan 2008 04:11:04 -0800 (PST)
Local: Sun, Jan 13 2008 7:11 pm
Subject: template declaration
Hi Everyone,

 we use the following in the template declaration,

template <class T>

template<typename T>

 Is it that typename is preferred as it can be used for all types,
where as class can only be used for custom class types?

Thanks in advance!!!


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Wikström  
View profile  
 More options Jan 13 2008, 7:23 pm
Newsgroups: comp.lang.c++
From: Erik Wikström <Erik-wikst...@telia.com>
Date: Sun, 13 Jan 2008 12:23:51 GMT
Local: Sun, Jan 13 2008 7:23 pm
Subject: Re: template declaration
On 2008-01-13 13:11, Rahul wrote:

> Hi Everyone,

>  we use the following in the template declaration,

> template <class T>

> template<typename T>

>  Is it that typename is preferred as it can be used for all types,
> where as class can only be used for custom class types?

No, whether you use class or typename here does not matter as far as the
compiler is concerned. I prefer to use typename and only use class for
class declarations.

--
Erik Wikström


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry  
View profile  
 More options Jan 13 2008, 10:35 pm
Newsgroups: comp.lang.c++
From: Barry <dhb2...@gmail.com>
Date: Sun, 13 Jan 2008 23:35:24 +0800
Local: Sun, Jan 13 2008 10:35 pm
Subject: Re: template declaration

Rahul wrote:
> Hi Everyone,

>  we use the following in the template declaration,

> template <class T>

> template<typename T>

>  Is it that typename is preferred as it can be used for all types,
> where as class can only be used for custom class types?

> Thanks in advance!!!

Both keywords have the same effect here, so it's just a coding style issue.
IIRC, according to "C++ Template: The complete Guide":

when the template parameter is not always a "class type"(including
/class/ /struct/, /union/), in this case, use /typename/:

e.g.

template <typename T>
class A { T t; };

class B {};

A<B>   a1;
A<int> a2; // int is not a class type

In the case when the template parameter should be a "class type", use
/class/,

Additionally, when the template argument is of template template
argument, only /class/ can be used.

e.g.

template <template <typename> class TT>
                               ^^^^^
class A;

HTH

--
Thanks
Barry


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google