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: <1993Jan8.174434.7714@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>
- Date: Fri, 8 Jan 1993 17:44:34 GMT
- Lines: 45
-
- In article <1993Jan8.154446.17174@dayfac.cdc.com> pault@dayfac.cdc.com (Paul Thompson;DAYFAC-ITS;) writes:
- >First off, thanks to all those who responded to my question and my
- >apologies for not being clear. I probably should have chosen a different
- >phrasing of the problem and certainly should have explained it better!
- >First to answer the replies received so far and I will clarify.
-
- You missed mine?
- >
- >WHAT I AM INTERESTED IN IS THE FUNCTIONALITY OF "COUNTING ONE'S
- >OWN INSTATIATIONS", NOT COUNTING THE TOTALITY OF ALL INSTATIATIONS OF
- >CLASS A.
-
- class A {
- int & counter;
- public:
- A(int& c) : counter(c) {++counter;}
- ~A() { --counter; }
- };
-
- class B : public virtual A {
- static int counter;
- public:
- B() : A(counter) { ... }
- };
-
- int B::counter=0;
-
- Without templates. Exercise: Prove it works! Prove you cannot
- get away without declaring and defining the counter in
- each class manually.
-
- 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.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-