home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Restatement and clarification of "static inheritance" question
- Message-ID: <1993Jan9.154850.5939@ucc.su.OZ.AU>
- Keywords: inheritance
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1993Jan8.154446.17174@dayfac.cdc.com> <1993Jan8.174434.7714@ucc.su.OZ.AU> <1ikg2tINN2d3@news.cerf.net>
- Date: Sat, 9 Jan 1993 15:48:50 GMT
- Lines: 50
-
- In article <1ikg2tINN2d3@news.cerf.net> hlf@nic.cerf.net (Howard Ferguson) writes:
- >>>WHAT I AM INTERESTED IN IS THE FUNCTIONALITY OF "COUNTING ONE'S
- >>>OWN INSTATIATIONS", NOT COUNTING THE TOTALITY OF ALL INSTATIATIONS OF
- >>>CLASS A.
-
- >>There are a number of possible ways that might fix this using templates.
- >>You would have to do something like:
- >>
- >> class B : public virtual A<B> { ...
- >>
- >>which seems dubious. Then the template class A<T> could create
- >>the int A<T>::counter automagically. Dont know if this
- >>works.
- >>
- >
- >I still do not see a reason for inheritance when containment will do.
- >Can anybody clarify this???
- >
-
- Sure. If you use containment you end up counting
- subobjects of the base classes too:
-
- class X { A<X> ax; };
- class Y { A<Y> ay; };
- class Z { A<Z> az; };
-
- Z z;
-
- // WOOPS: now we count 1 Z (correct) and 1 X and 1 Y (wrong)
-
- In fact: if you actually WANT to count subobjects, then
- DO use containment.
-
- Do you want to count 'new'ed classes or ALL subobjects?
-
- Wait! It is WORSE:
-
- class Q { X x; Y y; A<Z>; };
-
- This counts 1 'X' object: for BOTH containment (shown) or
- the inheritance method.
-
- OH! You have posed a really HARD problem.
- Mm .. overload operator new??
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-