Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   typename or class? (http://www.velocityreviews.com/forums/t946553-typename-or-class.html)

nietoperz34 05-26-2012 12:30 PM

typename or class?
 
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);

Saeed Amrollahi 05-26-2012 01:52 PM

Re: typename or class?
 
On May 26, 4:30*pm, nietoperz34 <hubo...@gmail.com> 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

nietoperz34 05-26-2012 08:59 PM

Re: typename or class?
 
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.


All times are GMT. The time now is 08:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.