🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #139

template overloading

#139
From: Marc Girod
Date: Fri, 11 Sep 1992 11:15
46 lines
2255 bytes
Someone proposed some time ago that a void type would be created,
which would be guarrantied to be of null length, which eventually gave
birth to various threads.

The originally alleged use for such a type would have been a special
use of certain templates, as follows:

template <class A, class B> class X;

X<int, void> x;

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."

This sounds like g++ was right (apart from allowing the superseeding
to occur, additionally without warning).

But now, why? What would be the problem? Wouldn't it be more natural
to allow template name overloading?
--
+-----------------------------------------------------------------------------+
| Marc Girod - Nokia Telecommunications       Phone: +358-0-511 7703          |
| TL4E - P.O. Box 12                            Fax: +358-0-511 7432          |
| SF-02611 Espoo 61 - Finland              Internet: marc.girod@ntc.nokia.com |
|    X.400: C=FI, A=Elisa, P=Nokia Telecom, UNIT=TRS, SUR=Girod, GIV=Marc     |
+-----------------------------------------------------------------------------+
Technical Details
Message-ID: <GIROD.92Sep11131510@node_262d6.tele.nokia.fi>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!news.funet.fi!ajk.tele.fi!funic!nokia.fi!tele.nokia!girod

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!news.funet.fi!ajk.tele.fi!funic!nokia.fi!tele.nokia!girod
From: girod@tele.nokia.fi (Marc Girod)
Subject: template overloading
Message-ID: <GIROD.92Sep11131510@node_262d6.tele.nokia.fi>
Sender: usenet@noknic.nokia.fi (USENET at noknic)
Nntp-Posting-Host: rat.ts.tele.nokia.fi
Reply-To: marc.girod@ntc.nokia.com
Organization: kpd
Distribution: comp
Date: Fri, 11 Sep 1992 11:15:10 GMT
Lines: 46