Why would you need to remove a typename?
Typename is required when using a dependant type.
Beats me. I'm the C guy, you're the C++ one.
Code:$ cat rectemp.cpp #include <iostream> using std::cout; template<int N> struct TemplateTest { static const int value = typename TemplateTest<N - 1>::value; }; template<> struct TemplateTest<0> { static const int value = 0; }; int main() { cout << TemplateTest<2>::value; } $ g++ rectemp.cpp -o rectemp rectemp.cpp:7: error: expected `(' before ';' token $
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
+Code:#include <iostream> using std::cout; template<int N> struct TemplateTest { static const int value = 1 + TemplateTest<N - 1>::value; }; template<> struct TemplateTest<0> { static const int value = 0; }; int main() { cout << TemplateTest<1000>::value; }
= success.-ftemplate-depth-1000
Such things are (should be) configurable.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Well, beats me why it doesn't like the typename keyword. Visual C++ compiles fine either way (but it's known to compile without the typename keyword anyway).
EDIT: Oh wait, I know. Of course, ::value is static, that's why it's not allowed.
No. You use 'typename' in that context to tell the language that you expect the nested type to be a type. In the error case it wasn't a type.Oh wait, I know. Of course, ::value is static, that's why it's not allowed.
Another fun internal error crash (for GCC and MSVC): use the relevant syntactical sugar--different for each compiler--to pass the address of a method to a template parameter and access that parameter in a context expected of a type. (The source should be flagged as illegal.)
Soma