"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> wrote in message
news:Xn**********************************@195.129. 110.204...
Domenico Andreoli wrote in news:86Qsb.112809$vO5.4389182
@twister1.libero.it: so the following breaks? why?
template <typename T>
struct A
{
T t;
};
void f()
{
enum B { zero, one };
A<B> t;
}
The name B doesn't have external linkage. If you consider adding:
Exact. IOW templates base there external-linkage on the external-linkage
of there arguments.
Which from a typical implementation's perspective means that
the name of the parameter type is mangled into (used as part of)
the name of template instanciation.
This is how the standard was/is writen. It could have been otherwise,
but would the benefits outway the cost (for implementers this is
man-hour's of programming, for us it's more waiting for fully
conforming compiler's).
Maybe, but this is debatable. Since the compiler has support for
anonymous namespaces, it knows how to generate unique names
already.
Many find this limitation is especially annoying when writing
functors and predicates:
void sortByAge(std::vector<Item>& items)
{
struct AgeCompare {
bool operator()(Item const& a, Item const&b)
{ return a.age<b.age; }
};
std::sort(items.begin(),items.end(),AgeCompare()); //error
}
Because AgeCompare has no external linkage, it has to be
moved out of the function. Ugly.
I'm pretty sure that dropping this limitation has been proposed
for the next C++ standard...
Regards,
Ivan
--
http://ivan.vecerina.com