Igor
Mon Jul 21 12:13:29 CDT 2008
bdachev@gmail.com wrote:
>> Yes, but it's little tricky: per the current standard a local class
>> does not have linkage. It's not internal linkage, it's not external
>> linkage, it's no linkage (no linkage essentially means "cannot be
>> referred to from other scopes"). E.g. you can't use it as a template
>> parameter.
>>
>> I think that's where Visual C++ stumbles.
>
> I also tried to use class locally defined in function as a template
> argument in VS.2005 and it compiles with no errors. So once again
> there is a problem following the C++ standard!
The upcoming C++0x standard will reportedly allow local classes as
template arguments.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2402.pdf
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm
This is deemed important to encourage using STL algorithms like for_each
in place of hand-written loops. As it stands now, local class can't be
used as a functor in for_each and has to be moved out of the function,
which makes the code less readable since the "body of the loop" is now
far away from surrounding code.
Apparently, authors of VC2005 attempted to implement this feature as an
extension, but didn't quite take all the consequences into account and
broke something else in the process. Accoring to Doug, this appears to
have been fixed in VC2008.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925