home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!usc!news.cerf.net!nic.cerf.net!hlf
- From: hlf@nic.cerf.net (Howard Ferguson)
- Newsgroups: comp.lang.c++
- Subject: Re: Restatement and clarification of "static inheritance" question
- Date: 8 Jan 1993 18:10:37 GMT
- Organization: CERFnet Dial n' CERF Customer Group
- Lines: 38
- Sender: hlf@cerf.net
- Message-ID: <1ikg2tINN2d3@news.cerf.net>
- References: <1993Jan8.154446.17174@dayfac.cdc.com> <1993Jan8.174434.7714@ucc.su.OZ.AU>
- NNTP-Posting-Host: nic.cerf.net
- Keywords: inheritance
-
- >>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.
- >
-
- I still do not see a reason for inheritance when containment will do.
- Can anybody clarify this???
-
- hlf
-
-