We can have a local class defined inside a function but this class cannot be a template which is bit annoying and inconsistent. Is there any update on that in C++0x standard?
Share
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.
Yes. Actually this rule change is what makes Lambda expressions possible since a Lambda expression creates a local unnamed type.Sorry, I misread your question. I thought you were talking about using a local class as template parameter. This wasn’t allowed in C++98 and C++03 but it will work in C++0x.
As for your actual question, C++0x will not change any of this.
I honestly see no reason to allow “function-local class templates”. The support for “function-local class templates” is a feature that probably only a handful of people care about. And writing class templates outside of functions is an acceptable substitute for this. This obviously doesn’t put enough pressure on the compiler vendors no matter how complicated it is to implement such a feature. Compiler vendors are probably more concerned about implementing other C++0x features.
But I understand your point. It may seem as an unnecessary irregularity of the language. If you care strongly about this feature you could write a formal proposal and send it to the C++ standardization committee in about two years when they are likely to accept proposals for “C++1y”.