Topic: Virtual static data members ?


Author: basile@soleil.serma.cea.fr (Basile STARYNKEVITCH)
Date: Mon, 20 Dec 1993 14:49:52 GMT
Raw View
I never understood why there are no virtual static data members. It
seems to me that there are easy to implement (just add another pointer
in the virtual tables). A typical usage would be some metadata, eg the
class name; For instance,

 class A {
     static virtual const char *name;
     void print_name(void) {
      cout << name ;
     };
 };

 class B : public a {
     static const char *name = "B";
     int x;
     B(int xx) { x= xx; }
 }

 B p = 1;
 p.print_name();

Should print B. Of course, i could define a virtual member function get_name()
but i think defining virtual data is simpler for both the programmer and the compiler?
(and same problems should occur for function and data conflicts).

Any comments? Please email or post.

---

Basile STARYNKEVITCH   ----  Commissariat a l Energie Atomique
DRN/DMT/SERMA * C.E. Saclay bat.470 * 91191 GIF/YVETTE CEDEX * France
fax: (33) 1- 69.08.23.81;    phone: (33) 1- 69.08.40.66
email: basile@soleil.serma.cea.fr;  homephone: (33) 1- 46.65.45.53


N.B. Any opinions expressed here are solely mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.






Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Tue, 21 Dec 1993 06:22:10 GMT
Raw View
In article <1993Dec20.144952.12832@nenuphar.saclay.cea.fr> basile@soleil.serma.cea.fr writes:
>I never understood why there are no virtual static data members. It
>seems to me that there are easy to implement

 Exactly the reason. They're so easy to implement,
a C++ programmer can do it in C++. Since the need is not
clearly demonstrated, its not in the language.

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA