home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16462 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.7 KB  |  41 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!agate!doc.ic.ac.uk!mrccrc!warwick!bham!bhamvx!mccauleyba
  3. From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
  4. Subject: Re: Compiler Bug (AT&T 2.1) ?
  5. Sender: usenet@rs6000.bham.ac.uk (USENET News Service)
  6. Message-ID: <1992Nov17.212613.1@vax1.bham.ac.uk>
  7. Date: Tue, 17 Nov 1992 21:26:13 GMT
  8. Lines: 29
  9. References: <1992Nov17.181306.8081@lut.ac.uk>
  10. Organization: University of Birmingham
  11.  
  12. In article <1992Nov17.181306.8081@lut.ac.uk>, J.March@lut.ac.uk writes:
  13. > Consider:
  14. > class Elt { public: Elt(int*); };
  15. > class List { public: List(const Elt&); }; 
  16. > void main() { List L(new int(1)); }
  17.   ^?^
  18.    [example cut down to relevant bits ]
  19. >
  20. > Shouldn't this fail because the declaration of L doesn't match any of 
  21. >         the constructors for class List?
  22. No, the complier is allowed to insert up to one user-supplied type
  23. conversion for each parameter in any parameter matching situation
  24. (except templates).
  25.  
  26. Since the type conversion constructor (aka one parameter constructor)
  27. Elt::Elt(int*) has been declared the complier can compile main() as:
  28.  
  29. main() { List L(Elt(new int(1))); }
  30.  
  31. This is now an exact match.
  32.  
  33. A tempoary Elt is created to satisfy the need for a reference to an Elt.
  34. -- 
  35.     \\   ( )    No Bullshit!     |  Email: B.A.McCauley@bham.ac.uk   
  36.  .  _\\__[oo        from         |  Voice: +44 21 471 3789 (home)
  37. .__/  \\ /\@    /~)  /~[   /\/[  |    Fax: +44 21 625 2175 (work)
  38. .  l___\\      /~~) /~~[  /   [  |  Snail: 197 Harborne Lane,
  39.  # ll  l\\    ~~~~ ~   ~ ~    ~  |         Birmingham, B29 6SS, UK
  40. ###LL  LL\\   (Brian McCauley)   |   ICBM: 52.5N 1.9W
  41.