home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pmafire!mica.inel.gov!ux1!news.byu.edu!eff!sol.ctr.columbia.edu!ira.uka.de!uka!news!hf
- From: hf@telematik.informatik.uni-karlsruhe.de (Harald Fuchs)
- Newsgroups: comp.lang.c++
- Subject: Re: Wisdom on f(...,const class& xxx = default_xxx)
- Date: 15 Nov 92 16:07:22
- Organization: Karlsruhe University, Germany
- Lines: 30
- Message-ID: <HF.92Nov15160722@whyaduck.telematik.informatik.uni-karlsruhe.de>
- References: <mg.721758488@tyrolia> <1992Nov14.221530.1@vax1.bham.ac.uk>
- NNTP-Posting-Host: whyaduck.telematik.informatik.uni-karlsruhe.de
- In-reply-to: mccauleyba@vax1.bham.ac.uk's message of Sat, 14 Nov 1992 22:15:30 GMT
-
- In article <1992Nov14.221530.1@vax1.bham.ac.uk>, mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
-
- > In article <mg.721758488@tyrolia>, mg@tyrolia (Michael Golan) writes:
- >> what's the net wisdom on a default parameter which is a class?
- >> in
- >> void f(...,int x = 0 ); or
- >>
- >> It is inexpensive for the caller to supply x.
- >> However, in
- >> void f(..., const T& = T(0)) ;
- >>
- >> The cost for the caller (to create T(0)) can be pretty expensive.
- >>
- >> My best solution is
- >> T Default_T(0) ; // global default class T
- >> void f(...., const T& = Default_T);
- >>
- >> But this goes "against" OO, and pollute the name space. Anyone has a better
- >> solution (trick?)
- > What I do in this situation is same except I'd use `T::Default' rather
- > than `Default_T'. (Where T::Default is a static const member of T).
- > Much less name space poluting and slightly more OO.
-
- Only slightly :-)
- "Default" probably belongs to "f", not to "T". The thing that isn't OO
- here is the global function "f". Put it in a class, and add a static
- "Default" member.
- --
-
- Harald Fuchs <hf@telematik.informatik.uni-karlsruhe.de>
-