J
Jakob Bieling
Hi,
I recently switched compilers (VC++7.1 to VC++8) and it started
complaining about my use of 'typename' in template classes. So far, I
have never fully understood where I need to put 'typename' and where
not. Please consider the following snippet:
#include <list>
template <typename T>
struct test_case
{
test_case (/* (1) */T::iterator i = (/* (2) */T::iterator ())
{
(/* (3) */T::iterator ii;
}
};
int main (int argc, char* argv [])
{
test_case <std::list <int> > foo;
}
As you can see, I marked three spots. In (1), the compiler requires
me to put 'typename'. In (2) I am not allowed to. In (3) it compiles
with or without.
Why those differences? And what is the reasoning behind requiring it
at all?
Thanks for your time!
I recently switched compilers (VC++7.1 to VC++8) and it started
complaining about my use of 'typename' in template classes. So far, I
have never fully understood where I need to put 'typename' and where
not. Please consider the following snippet:
#include <list>
template <typename T>
struct test_case
{
test_case (/* (1) */T::iterator i = (/* (2) */T::iterator ())
{
(/* (3) */T::iterator ii;
}
};
int main (int argc, char* argv [])
{
test_case <std::list <int> > foo;
}
As you can see, I marked three spots. In (1), the compiler requires
me to put 'typename'. In (2) I am not allowed to. In (3) it compiles
with or without.
Why those differences? And what is the reasoning behind requiring it
at all?
Thanks for your time!