Newsgroups: comp.lang.c++
Path: utzoo!utgpu!watserv1!watmath!watmsg!gjditchfield
From: gjditchfield@watmsg.uwaterloo.ca (Glen Ditchfield)
Subject: Whatever happened to virtual data?
Message-ID: <1991Mar7.204853.22289@watmath.waterloo.edu>
Sender: daemon@watmath.waterloo.edu (0000-Admin(0000))
Organization: University of Waterloo
Date: Thu, 7 Mar 1991 20:48:53 GMT
Lines: 44

This may be all a caffeine dream, but I think that, a while back, serious
consideration was being given to the idea of "virtual data".  I think the
idea was that a base class would define a virtual data member, and that
derived classes could redefine its value.  Like a virtual function, a
virtual data member would be shared by all instances of a class and any
derived classes that did not redefine it.  Unlike static members, it would
not be shared with instances of derived classes that did redefine it.
   This seems something like what two recent posters were asking for:

>ahuttune Thu Mar  7 13:12:23 EST 1991
>
>Situation: I have found that in many cases I have a base class from which
>a large number of other classes have been derived. In _each_ of the derived
>classes I need a piece of information that is, in a sense, identical. ...
>The example that follows is usable in a game not unlike nethack, though
>I am certain it can be applied to more 'serious uses'. In nethack you
>don't know _exactly_ which object is which until you identify them. 
>The important point is that identifying _any_ object of a certain class
>identifies _all_ objects of this class, but not of any other class.
 [His example: class Lamp with descendants NormalLamp and MagicalLamp.  A
  Lamp* happens to point at a MagicalLamp.  Identifying the thing it points
  at causes all MagicalLamps to be marked "identified", but has no effect
  on the NormalLamps.]

>rosebud.llnl.gov Thu Mar  7 14:46:58 EST 1991
>I have a class that looks like:
>class class_a
>  {
>    static int a_var;
>    int b_var;
>  }
>This works fine except that now, it turns out, I need another set of
>objects that do the exact same thing, except with a different a_var.
>The only way I've been able to do this, has been to copy class_a and
>rename it.  I would much rather do this by using class_a as the source
>for both.  It seems I would need to form two subclasses or derived
>classes of class_a that don't share a_var.

(Sorry about the lost attribution lines.)

Virtual data might also help programmers who want to implement their own
type tests.
   My guess is that the proposal was dropped because virtual functions
could provide the facility without much ugliness.
