home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1153 < prev    next >
Encoding:
Text File  |  1992-09-11  |  2.1 KB  |  60 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!mcsun!news.funet.fi!ajk.tele.fi!funic!nokia.fi!tele.nokia!girod
  3. From: girod@tele.nokia.fi (Marc Girod)
  4. Subject: template overloading
  5. Message-ID: <GIROD.92Sep11131510@node_262d6.tele.nokia.fi>
  6. Sender: usenet@noknic.nokia.fi (USENET at noknic)
  7. Nntp-Posting-Host: rat.ts.tele.nokia.fi
  8. Reply-To: marc.girod@ntc.nokia.com
  9. Organization: kpd
  10. Distribution: comp
  11. Date: Fri, 11 Sep 1992 11:15:10 GMT
  12. Lines: 46
  13.  
  14. Someone proposed some time ago that a void type would be created,
  15. which would be guarrantied to be of null length, which eventually gave
  16. birth to various threads.
  17.  
  18. The originally alleged use for such a type would have been a special
  19. use of certain templates, as follows:
  20.  
  21. template <class A, class B> class X;
  22.  
  23. X<int, void> x;
  24.  
  25. This made me wonder whether it was possible to overload template
  26. definitions, such as:
  27.  
  28. template <class A> class X {};
  29. template <class A, class B> class X {};
  30.  
  31. X<int> x1;       //from the first template
  32. X<int, int> x2;  //from the second
  33.  
  34. I checked with g++ v2.2.2, and was surprised to notice that the
  35. overriding of the templates was legal, but thus hid the former
  36. declaration, without any warning. The result was thus an error, at
  37. delaration time of x1:
  38.  
  39. incorrect number of parameters (1, should be 2) in template expansion
  40.  
  41. Well, I had a look in ARM, and couldn't find anything better than:
  42.  
  43. p 347
  44. 14.5c Declarations and Definitions
  45. "There must be exactly one definition for each template of a given
  46. name in a program."
  47.  
  48. This sounds like g++ was right (apart from allowing the superseeding
  49. to occur, additionally without warning).
  50.  
  51. But now, why? What would be the problem? Wouldn't it be more natural
  52. to allow template name overloading?
  53. --
  54. +-----------------------------------------------------------------------------+
  55. | Marc Girod - Nokia Telecommunications       Phone: +358-0-511 7703          |
  56. | TL4E - P.O. Box 12                            Fax: +358-0-511 7432          |
  57. | SF-02611 Espoo 61 - Finland              Internet: marc.girod@ntc.nokia.com |
  58. |    X.400: C=FI, A=Elisa, P=Nokia Telecom, UNIT=TRS, SUR=Girod, GIV=Marc     |
  59. +-----------------------------------------------------------------------------+
  60.