🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2542

Virtual static members

#2542
From: David Harley
Date: Mon, 13 Nov 1995 17:24
27 lines
1102 bytes
Is there any good reason why the following is disallowed?

class A
{
  virtual static s;
  f() { do something with s }
}

class B : A
{
  virtual static s;
...
}

 - the idea being, that each subclass of A can posess its own static member
that doesn't interfere with other subclasses, but which can be accessed
by methods of A.

The only work-around seems to be to declare s as non-static in A, and then
assign the static variable in the B's to A's s in B's constructor's (maybe
I should have used x instead of s!)

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <487q1e$peq@aztec.co.za>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: dharley@aztec.co.za (David Harley)
Newsgroups: comp.std.c++
Subject: Virtual static members
Date: 13 Nov 1995 17:24:49 GMT
Organization: Aztec Public Access Internet
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <487q1e$peq@aztec.co.za>
NNTP-Posting-Host: physics2.berkeley.edu