home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16322 next >
Encoding:
Internet Message Format  |  1992-11-15  |  1.7 KB

  1. Path: sparky!uunet!pmafire!mica.inel.gov!ux1!news.byu.edu!eff!sol.ctr.columbia.edu!ira.uka.de!uka!news!hf
  2. From: hf@telematik.informatik.uni-karlsruhe.de (Harald Fuchs)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Wisdom on f(...,const class& xxx = default_xxx)
  5. Date: 15 Nov 92 16:07:22
  6. Organization: Karlsruhe University, Germany
  7. Lines: 30
  8. Message-ID: <HF.92Nov15160722@whyaduck.telematik.informatik.uni-karlsruhe.de>
  9. References: <mg.721758488@tyrolia> <1992Nov14.221530.1@vax1.bham.ac.uk>
  10. NNTP-Posting-Host: whyaduck.telematik.informatik.uni-karlsruhe.de
  11. In-reply-to: mccauleyba@vax1.bham.ac.uk's message of Sat, 14 Nov 1992 22:15:30 GMT
  12.  
  13. In article <1992Nov14.221530.1@vax1.bham.ac.uk>, mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
  14.  
  15. > In article <mg.721758488@tyrolia>, mg@tyrolia (Michael Golan) writes:
  16. >> what's the net wisdom on a default parameter which is a class?
  17. >> in
  18. >> void f(...,int x = 0 );            or 
  19. >> 
  20. >> It is inexpensive for the caller to supply x.
  21. >> However, in
  22. >> void f(..., const T& = T(0)) ;
  23. >> 
  24. >> The cost for the caller (to create T(0)) can be pretty expensive.
  25. >> 
  26. >> My best solution is 
  27. >>   T Default_T(0) ;    // global default class T
  28. >>   void f(...., const T& = Default_T);
  29. >> 
  30. >> But this goes "against"  OO, and pollute the name space. Anyone has a better
  31. >> solution (trick?)
  32. > What I do in this situation is same except I'd use `T::Default' rather
  33. > than `Default_T'. (Where T::Default is a static const member of T).
  34. > Much less name space poluting and slightly more OO.
  35.  
  36. Only slightly :-)
  37. "Default" probably belongs to "f", not to "T". The thing that isn't OO
  38. here is the global function "f". Put it in a class, and add a static
  39. "Default" member.
  40. --
  41.  
  42. Harald Fuchs <hf@telematik.informatik.uni-karlsruhe.de>
  43.