void foo() {
struct Foo { .. };
std::vector<Foo> vec; // why is this illegal?
}
I’m not returning Foo to the outside world. It’s just a temporary type that I use within the function.
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.
A local class can’t be a template argument. Because the standard says:-
14.3.1 paragraph 2:
“A local type, a type with no linkage, an unnamed type or a type
compounded from any of these types shall not be used as a
template argument for a template type parameter.”
One workaround is suggested here on c.l.c++.moderated.
UPDATE:
There was some discussion on why is it not possible to have local-classes as template arguments? The links here and here on c.std.c++ discuss the same.