Why do you sometimes need to write <typename T> instead of just <T> ?
Posted
by StackedCrooked
on Stack Overflow
See other posts from Stack Overflow
or by StackedCrooked
Published on 2009-08-08T00:13:10Z
Indexed on
2010/05/01
15:47 UTC
Read the original article
Hit count: 160
I was reading the Wikipedia article on SFINAE and encountered following code sample:
struct Test
{
typedef int Type;
};
template < typename T >
void f( typename T::Type ) {} // definition #1
template < typename T >
void f( T ) {} // definition #2
void foo()
{
f< Test > ( 10 ); //call #1
f< int > ( 10 ); //call #2 without error thanks to SFINAE
}
Now I've actually written code like this before, and somehow intuitively I knew that I needed to type "typename T" instead of just "T". However, it would be nice to know the actual logic behind it. Anyone care to explain?
© Stack Overflow or respective owner