Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > typename or class?

Reply
Thread Tools

typename or class?

 
 
nietoperz34
Guest
Posts: n/a
 
      05-26-2012
Welcome. What better use in templates C++? Typename or class?
Better yes:
template <class T1, class T2>
T1 function(T2 argument);
Or better yes:
template <typename T1, typename T2>
T1 function(T2 argument);
 
Reply With Quote
 
 
 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      05-26-2012
On May 26, 4:30*pm, nietoperz34 <(E-Mail Removed)> wrote:
> Welcome. What better use in templates C++? Typename or class?
> Better yes:
> template <class T1, class T2>
> T1 function(T2 argument);
> Or better yes:
> template <typename T1, typename T2>
> T1 function(T2 argument);


Hi
Actually from point of programming language usage
using class and typename in template declaration/definition are same.
For who likes less typing, class is shorter than typename.
I believe programmers has some personal convention for using class or
typename. For example Andrei Alexandrescu wrote in his book
Modern C++ Design:
Template parameters are declared with class if they can be only a user-
defined type, and with
typename if they can also be a primitive type.
But, please note: typename has another totally separated usage when
programming
templates. For example:
template<class Container>
void SomeFunc(Container c)
{
typename Container::ElemType e; // You have to use typename
// ...
}

In above line, you can't use 'class' instead of 'typename'

HTH,
-- Saeed Amrollahi
 
Reply With Quote
 
 
 
 
nietoperz34
Guest
Posts: n/a
 
      05-26-2012
W dniu sobota, 26 maja 2012 14:30:44 UTC+2 użytkownik nietoperz34 napisał:
> Welcome. What better use in templates C++? Typename or class?
> Better yes:
> template <class T1, class T2>
> T1 function(T2 argument);
> Or better yes:
> template <typename T1, typename T2>
> T1 function(T2 argument);


Hi. I will use class, because shorter. Thanks, nietoperz34.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class vs. typename Alexander Malkis C++ 7 10-20-2012 09:03 PM
Q: typename or not typename? Jakob Bieling C++ 2 03-14-2006 03:44 PM
implicit typename in template Steve Hill C++ 1 09-06-2003 07:52 AM
typename, typedef, and resolution Gina Yarmel C++ 4 08-13-2003 04:06 PM
Gcc complain about typename Xavier Decoret C++ 1 07-04-2003 05:27 AM



Advertisments