home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!udecc.engr.udayton.edu!udcps3!dayfac!pault
- From: pault@dayfac.cdc.com (Paul Thompson;DAYFAC-ITS;)
- Subject: static "inheritance" question
- Message-ID: <1993Jan4.144320.5586@dayfac.cdc.com>
- Summary: how to inherit static class members or do the equivalent
- Organization: Control Data Corporation, Dayton, Ohio
- Date: Mon, 4 Jan 93 14:43:20 GMT
- Lines: 32
-
- Consider class A which counts its 'live' instantiations.
-
- class A {
- static int nr;
- public:
- A() {nr++;}
- ~A() {nr--;}
- int getNrInstances () {return nr;}
- };
- ...
- A::nr = 0;
-
- A has useful functionality which I would like to use in other
- classes with MINIMAL change to the other classes. One way
- is to try:
-
- class B :public A { ....};
- class C :public A { ....};
- ...
- B b1, b2, b3;
- C c1, c2;
- cout << B::getNrInstances();
-
- But this doesnUt work because static variables aren't inherited
- (at least not in my compiler).
- Could anyone enlighten me as to how to acquire the functionality
- of a class like A that depends on a static variable with LEAST
- modification to the acquiring class ? Thanks.
-
- pault@dayfac.cdc.com
-
-
-