template <class T> T f() { }
template <typename T> T g() { }
Thanks,
Jason
> Is there any difference between declaring a template parameter as a
> "typename" or a "class"? E.g.
No. They are equivalent.
Yes: 'class' is more confusing because the type might not actually be
a class at all.
And typename is more confusing because it has other uses as well. :-)
template<typename Container, typename Container::value_type>
class something;
One typename is the same as class, but not the other. Isn't that
confusing?
Bo Persson
template<class T>
class Foo { };
One class is the same as typename, but not the other. Isn't that
confusing? :-)
Seriously though, there is at least one instance where they are not
identical:
template<template<typename U> class T>
class Foo { };
--
Erik Wikström
As others have said, in this case "class" and "typename" have identical
semantics.
That said, I tend to use them both in templates as sort of
documentation, and a usage aid.
e.g.:
template<typename T> something... indicates that T can be any type
template<class T> something... indicates that T should be a class type.
Follow up note, to remove all confusion.
This is merely a *coding convention* that *I use*, it is not mandated by
the language.
Btw, is there any tutorial or other resources in the net which would
explain in detail all that can be done with templates?
Usually you can find just the basic usage and that's it.
If you want that level of detain, get hold of a copy of the excellent
"C++ Templates" by Vandevoorde and Josuttis.
--
Ian Collins.
Yes, in some places you must use class, in some places you must use
typename, and in other places you can use either.
This really *is* confusing, and I believe that there are now some
regrets for allowing this. Seemed like a good idea at the time, but...
Bo Persson
http://www.linuxtopia.org/online_books/programming_books/c++_practical_programming/c++_practical_programming_104.html
Have fun it's more than you'll ever need