Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Whatever happened to virtual data? Message-ID: <71205@microsoft.UUCP> Date: 11 Mar 91 21:43:54 GMT References: <1991Mar7.204853.22289@watmath.waterloo.edu> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 36 In article <1991Mar7.204853.22289@watmath.waterloo.edu> gjditchfield@watmsg.uwaterloo.ca (Glen Ditchfield) writes: |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. Today one would do this something like: class X { static int _virt_data; public: inline virtual int& virt_data() { return _virt_data; } // or get_virt_data(), set_virt_data(int) .... }; And that's all there is to it until one implements another class that wants a distinct _virt_data. Then a programmer has to re-implement the two lines that have _virt_data's on them, or alternatively, invoke a macro hack to create the two lines from one macro. There seems to be two issues here: 1) the ugliness required to implement this each time. 2) The speed of the resulting "inline virtual" call. Issue #2 can be solved, if a particular compiler cares enough, through the use of fat tables and/or customization instead of vtables. Thus issue #2 is not a language issue, but rather a quality-of-implementation issue. Issue #1 could be solved, or at least greatly improved, if the capabilities of templates were improved to allow greater applicability to member functions. Thus, I claim its not necessary to add virtual member variables, rather we should tweak the capabilities of templates.