Topic: Anonymous structs as template parameters.
Author: "emreturkay@gmail.com" <emreturkay@gmail.com>
Date: Fri, 5 Jan 2007 09:45:12 CST Raw View
Hi folks,
Does anybody know what does the standard say about it?
gcc complains when I try;
template < typename T > struct X { };
typedef X< struct { int i; } > new_X;
Thanks,
Emre Turkay
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Fri, 5 Jan 2007 23:38:44 CST Raw View
emreturkay@gmail.com wrote:
> Hi folks,
>
> Does anybody know what does the standard say about it?
> gcc complains when I try;
>
> template < typename T > struct X { };
> typedef X< struct { int i; } > new_X;
According to the C++ Standard, a class definition is a "type-id", and a
type-id can be used as a template type parameter (which I did not
know). And if that were all the Standard had to say on this topic, then
I think your declaration would be in great shape.
But what the Standard gives, it can also take away. And now, we've come
to the "taking away" part of my answer. And I don't see any point in
sugar-coating what has to follow, so I'll tell it to you straight: the
Standard bars any type without external linkage from being used as a
template type parameter. Since an anonymous class type (such as the one
in your example) does not have have external linkage, your example is
ill-formed. Nor would a named class definition fare any better. Because
the scope of a template type parameter is confined to the exent of the
template declaration itself, a named class definition would not have
the necessary external linkage either.
Greg
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]