This question covers when and why the typename and template disambiguators are needed in C++ template code.
Is it valid to use these disambiguators in cases where they are not needed in C++03? How about in C++11?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s valid in conforming C++03/C++11 compilers, for some definition of “valid.”
C++03 ISO/IEC 14882:2003 §14.2.5:
C++11 ISO/IEC 14882:2011 §14.2.5:
Note that you can’t use
templatewhen the member in question isn’t actually a template—you aren’t allow to lie with it. Also note that fortypename, the type has to be a qualified type (e.g.X::Y, not justX). C++11 also changed it so that you don’t have to be in the scope of a template, whereas C++03 required you to be in a template. Also note that compilers are likely to differ on whether they actually let you do this. Under Clang, for instance, this warns under the flag-Wc++11-extensions.Here are some examples, assuming the following definition:
Invalid in both C++03 and C++11:
Invalid in C++03, valid in C++11 (but produces a warning on my copy of Clang):
Valid in both C++03 and C++11: