S
StephQ
First of all: distinction of keywords typename and class in template
arguments.
Accoarding to a post in a well known moderated group:
"There are three possibilities for template arguments:
1) type as in "template <typename T>" or "template <class T>"
2) non-type as in "template <int N>"
3) class template as in "template <template<typename> class C>" "
Now, in 1 class and typename are equivalent.
1 is parametrizing the type of the object
2 is parametrizing which object
In 3 you have to use class, because C is just a template class.
But I admit I am a little confused here, what is exactly C? Could I
pass stl vector as C ? So template<typename> really means only that C
is a class template (and not a type), but actually could be defined by
more than 1 template argument? Where could I find a concrete easy
example?
Also, what is considered a good programming syntax? Using typename in
1 and 2, while class in 3?
Another problem I'm facing is that gcc requires the typename keyword
in a lot of situations, like:
template <class T>
void print(const std::vector<T>& vec)
{
std::vector<T>::const_iterator i;
...
}
warning: `std::vector<T, std::allocator<_CharT> >::const_iterator' is
implicitly a typename (deprecated)
I don't know where should I add the typename keyword, and why.
Thank you
Cheers
StepQ
p.s. Is there a way to write a print function once for list, vector,
deque, .... ?
arguments.
Accoarding to a post in a well known moderated group:
"There are three possibilities for template arguments:
1) type as in "template <typename T>" or "template <class T>"
2) non-type as in "template <int N>"
3) class template as in "template <template<typename> class C>" "
Now, in 1 class and typename are equivalent.
1 is parametrizing the type of the object
2 is parametrizing which object
In 3 you have to use class, because C is just a template class.
But I admit I am a little confused here, what is exactly C? Could I
pass stl vector as C ? So template<typename> really means only that C
is a class template (and not a type), but actually could be defined by
more than 1 template argument? Where could I find a concrete easy
example?
Also, what is considered a good programming syntax? Using typename in
1 and 2, while class in 3?
Another problem I'm facing is that gcc requires the typename keyword
in a lot of situations, like:
template <class T>
void print(const std::vector<T>& vec)
{
std::vector<T>::const_iterator i;
...
}
warning: `std::vector<T, std::allocator<_CharT> >::const_iterator' is
implicitly a typename (deprecated)
I don't know where should I add the typename keyword, and why.
Thank you
Cheers
StepQ
p.s. Is there a way to write a print function once for list, vector,
deque, .... ?