Topic: Access privileges of static members


Author: Hyman Rosen <hymie@prolifics.com>
Date: 2000/02/04
Raw View
"Ron" <nospam@this-address.org> writes:
> I think you compiler is correct. Since StaticObject is static, it isn't
> destroyed until main () exits. Therefore, its destructor isn't called from
> stat (), but, effectively, from main (). This means that its destructor must
> be publically-visible.

No. The visibility of the destructor is checked at the point where the
static object is defined. See 11/5 and 12.4/10.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Ron" <nospam@this-address.org>
Date: 2000/02/08
Raw View
"Hyman Rosen" <hymie@prolifics.com> wrote in message
news:t790122v98.fsf@calumny.jyacc.com...
> "Ron" <nospam@this-address.org> writes:
> > I think you compiler is correct. Since StaticObject is static, it isn't
> > destroyed until main () exits. Therefore, its destructor isn't called
from
> > stat (), but, effectively, from main (). This means that its destructor
must
> > be publically-visible.
>
> No. The visibility of the destructor is checked at the point where the
> static object is defined. See 11/5 and 12.4/10.

I don't see what 11.5 has to do with this question, but 12.4(10) does seem
to say that the destructor need be accessible only at the point at which a
static class-type object is declared. This hews more closely to the
need-to-know principle than does requiring the destructor to be public, too.

Thanks for the correction.

-- Ron Crane


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: kanze@gabi-soft.de
Date: 2000/02/08
Raw View
Hyman Rosen <hymie@prolifics.com> writes:

|>  "Ron" <nospam@this-address.org> writes:
|>  > I think you compiler is correct. Since StaticObject is static, it
|>  > isn't destroyed until main () exits. Therefore, its destructor
|>  > isn't called from stat (), but, effectively, from main (). This
|>  > means that its destructor must be publically-visible.

|>  No. The visibility of the destructor is checked at the point where the
|>  static object is defined. See 11/5 and 12.4/10.

Note, however, that these clauses were among the last things specified.
For most of its existance, the draft didn't say anything about the
context for access checking of destructors, and while the only
reasonable solution to me was to check at the point of declaration, most
compilers did not.  I suppose that VC++ was one of these, and that they
just haven't gotten around to fixing it.

--
James Kanze                               mailto:kanze@gabi-soft.de
Conseils en informatique orientie objet/
                  Beratung in Objekt orientierter Datenverarbeitung
Ziegelh|ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Oliver Lauer" <O.Lauer@ids-scheer.de>
Date: 2000/02/01
Raw View
Hi !
I have a question about access privileges.
Given this:
class A
{
  public:
    static A & stat();
  private:
      A()  {}
      ~A()  {}
};

A & A::stat()
{
  static A StaticObject;
  return StaticObject;
}

My Compiler (VC++6.0) complains to compile it, because it can not access
'~A' in the static method 'stat'.
However, AFAIK static methods have the same access privileges as normal
methods.
I could imagine the compiler applies global scope to the destructor
because
the variable 'StaticObject' is of static storage. But I think storage has
nothing to do with access-privileges.

The question is, is the above code standard conforming ? And who is wrong ?
Me or the compiler ?
Thanks


Oliver Lauer
email: o.lauer@ids-scheer.de



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Frans Meijer <kanga_roo@my-deja.com>
Date: 2000/02/03
Raw View
In article <s896ae13.026@ngw02.ids-scheer.de>,
  "Oliver Lauer" <O.Lauer@ids-scheer.de> wrote:
>
> I have a question about access privileges...
> class A
> {
>   public:
>     static A & stat();
>   private:
>       A()  {}
>       ~A()  {}
> };
>
> A & A::stat()
> {
>   static A StaticObject;
>   return StaticObject;
> }
>
> My Compiler (VC++6.0) complains to compile it, because it can
> not access '~A' in the static method 'stat'.
> ...
> The question is, is the above code standard conforming ? And
> who is wrong ? Me or the compiler ?

It is conforming, I think, you are right and the compiler is wrong. I
couldn't find anything special concerning access rights for destructors.


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]