home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!CSD-NewsHost.Stanford.EDU!Xenon.Stanford.EDU!ralph
- From: ralph@Xenon.Stanford.EDU (Ralph Melton)
- Subject: 'virtual' static members
- Message-ID: <1992Aug12.201004.1257@CSD-NewsHost.Stanford.EDU>
- Originator: ralph@Xenon.Stanford.EDU
- Sender: news@CSD-NewsHost.Stanford.EDU
- Organization: Computer Science Department, Stanford University.
- Date: Wed, 12 Aug 1992 20:10:04 GMT
- Lines: 39
-
-
- I am trying to write a general enumeration class that can do output
- of itself. If I was doing it as a single class, part of it might
- look like
-
- class myEnum
- {
- int value;
- static int names;
- friend ostream& operator<< (ostream&, myEnum&);
- //...
- }
-
- ostream& operator<< (ostream& os, myEnum& e);
- { return ( os << e.names[e.value] ); }
-
-
- This is all well and good, but I would like to make this into an
- abstract base class, so that for a specific type of MyEnum, you subclass
- myEnum, and give the subclass its own static "names" array.
- I would like to leave the operator<< function the same, if possible.
-
- Ideally, I would like to be able to define a fully functional
- subclass of myEnum in just one or two lines.
-
- Can this be done? If I don't declare the array in myEnum, this
- operator<< function can't see it; if I do declare it, I can't
- override it in subclasses.
-
- I think I can see more or less skanky ways around this problem using
- macros or specialized constructors; I am curious as to whether there
- is any way to declare a static member that is different for every
- subclass.
-
-
- Ralph Melton
- --
- Ralph Melton ralph@cs.stanford.edu
- "Then ye shall know the truth, and the truth shall make you free."
-