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
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!!!
You must
Sign in before you can post messages.
You do not have the permission required to post.
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
You must
Sign in before you can post messages.
You do not have the permission required to post.
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
You must
Sign in before you can post messages.
You do not have the permission required to post.