home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1160 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  1.8 KB

  1. Path: sparky!uunet!usc!rpi!bu.edu!att!att!allegra!alice!bs
  2. From: bs@alice.att.com (Bjarne Stroustrup)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: template overloading
  5. Message-ID: <23656@alice.att.com>
  6. Date: 11 Sep 92 18:44:03 GMT
  7. References: <GIROD.92Sep11131510@node_262d6.tele.nokia.fi>
  8. Distribution: comp
  9. Organization: AT&T Bell Laboratories, Murray Hill NJ
  10. Lines: 46
  11.  
  12.  
  13.  
  14. girod@tele.nokia.fi (Marc Girod @ kpd) writes
  15.  
  16.  > This made me wonder whether it was possible to overload template
  17.  > definitions, such as:
  18.  > 
  19.  > template <class A> class X {};
  20.  > template <class A, class B> class X {};
  21.  > 
  22.  > X<int> x1;       //from the first template
  23.  > X<int, int> x2;  //from the second
  24.  > 
  25.  > I checked with g++ v2.2.2, and was surprised to notice that the
  26.  > overriding of the templates was legal, but thus hid the former
  27.  > declaration, without any warning. The result was thus an error, at
  28.  > delaration time of x1:
  29.  > 
  30.  > incorrect number of parameters (1, should be 2) in template expansion
  31.  > 
  32.  > Well, I had a look in ARM, and couldn't find anything better than:
  33.  > 
  34.  > p 347
  35.  > 14.5c Declarations and Definitions
  36.  > "There must be exactly one definition for each template of a given
  37.  > name in a program."
  38.  
  39.  
  40. How about (pg343):
  41.  
  42.     A class template name must be unique in a program and may not
  43.     be declared to refer to any other template, class, function,
  44.     value, or type in the same scope.
  45.  
  46.  > This sounds like g++ was right (apart from allowing the superseeding
  47.  > to occur, additionally without warning).
  48.  
  49. No. That seems to be a g++ bug.
  50.  
  51.  > But now, why? What would be the problem? Wouldn't it be more natural
  52.  > to allow template name overloading?
  53.  
  54. It would be nice to be able to overload templates, but to do this we'd
  55. have to work out the exact overloading rules. That is not a trivial task,
  56. it hasn't been done, and there may be fundamental problems lurking.
  57. Hence the prohibition.
  58.