Article View: comp.std.c++
Article #148Re: template overloading
From: Bjarne Stroustrup
Date: Fri, 11 Sep 1992 18:44
Date: Fri, 11 Sep 1992 18:44
46 lines
1943 bytes
1943 bytes
girod@tele.nokia.fi (Marc Girod @ kpd) writes
> This made me wonder whether it was possible to overload template
> definitions, such as:
>
> template <class A> class X {};
> template <class A, class B> class X {};
>
> X<int> x1; //from the first template
> X<int, int> x2; //from the second
>
> I checked with g++ v2.2.2, and was surprised to notice that the
> overriding of the templates was legal, but thus hid the former
> declaration, without any warning. The result was thus an error, at
> delaration time of x1:
>
> incorrect number of parameters (1, should be 2) in template expansion
>
> Well, I had a look in ARM, and couldn't find anything better than:
>
> p 347
> 14.5c Declarations and Definitions
> "There must be exactly one definition for each template of a given
> name in a program."
How about (pg343):
A class template name must be unique in a program and may not
be declared to refer to any other template, class, function,
value, or type in the same scope.
> This sounds like g++ was right (apart from allowing the superseeding
> to occur, additionally without warning).
No. That seems to be a g++ bug.
> But now, why? What would be the problem? Wouldn't it be more natural
> to allow template name overloading?
It would be nice to be able to overload templates, but to do this we'd
have to work out the exact overloading rules. That is not a trivial task,
it hasn't been done, and there may be fundamental problems lurking.
Hence the prohibition.
Technical Details
Message-ID:
<23656@alice.att.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!rpi!bu.edu!att!att!allegra!alice!bsReferences:
<GIROD.92Sep11131510@node_262d6.tele.nokia.fi>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!rpi!bu.edu!att!att!allegra!alice!bs From: bs@alice.att.com (Bjarne Stroustrup) Newsgroups: comp.std.c++ Subject: Re: template overloading Message-ID: <23656@alice.att.com> Date: 11 Sep 92 18:44:03 GMT References: <GIROD.92Sep11131510@node_262d6.tele.nokia.fi> Distribution: comp Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 46