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: <1993Jan11.045542.6877@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: <1ikg2tINN2d3@news.cerf.net> <1993Jan9.154850.5939@ucc.su.OZ.AU> <1ipp5oINNg0e@news.cerf.net>
- Date: Mon, 11 Jan 1993 04:55:42 GMT
- Lines: 56
-
- In article <1ipp5oINNg0e@news.cerf.net> hlf@nic.cerf.net (Howard Ferguson) writes:
- >In article <1993Jan9.154850.5939@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- >>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.
- > -- stuff deleted --
- >>>
- >>>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)
- >
- >Have you missunderstood, and thought that there is only one static
- >created for all of the A's. (I think) you are wrong here. The template
- >semantics create one static for each class and A<X> is a different class
- >from A<Y> so thge result would be 1 Z , zero X's, and zero Y's.
- >
- Sorry: I messed the example!
- Try again:
-
- class X { A<X> ax; };
- class Y { A<Y> ay; };
- class Z {
- A<Z> az;
- X x; // containment!
- Y y;
- };
- Z z;
-
- Now the count for 'X' objects is 1.
-
- class ZZ : public X, public Y { // inheritance
- A<Z> az;
- };
- ZZ zz;
-
- Now the count for 'X' objects is 2.
-
- I'm assuming in this case you want Z==1, ZZ==1, X==0, Y==0?
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-