Topic: private dtor, static instance
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1997/10/17 Raw View
Michael R Cook <michael_cook%erawan@cognex.com> writes:
|> If my class's destructor is private, does that mean I'm not allowed
|> to create static instances of that of that class?
|>
|> For example:
|>
|> class C {
|> static C& only();
|> C();
|> ~C();
|> };
|> C& C::only()
|> {
|> static C c; // error?
|> return c;
|> }
|>
|> The dwp (Nov96) says:
|>
|> 12.4 Destructors [class.dtor]
|> 10 Destructors are invoked implicitly (1) for a constructed object
|> with static storage duration (_basic.stc.static_) at program
|> termination (_basic.start.term_), (2) [...]. A program is
|> ill-formed if the destructor for an object is implicitly used and
|> it is not accessible (_class.access_).
|>
|> But it doesn't say what context is used to determine the
|> accessibility of the destructor that would be invoked at program
|> termination. I would expect that the construction context would be
|> used. (Microsoft agrees. Gcc disagrees.)
This has been clarified since the CD2. The context for the
accessibility check of the destructor is the same as the declaration, so
the above code is legal.
Since this clarification is *very* recent, don't expect all compilers to
implement it yet.
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
I'm looking for a job -- Je recherche du travail
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Michael R Cook <michael_cook%erawan@cognex.com>
Date: 1997/10/16 Raw View
If my class's destructor is private, does that mean I'm not allowed
to create static instances of that of that class?
For example:
class C {
static C& only();
C();
~C();
};
C& C::only()
{
static C c; // error?
return c;
}
The dwp (Nov96) says:
12.4 Destructors [class.dtor]
10 Destructors are invoked implicitly (1) for a constructed object
with static storage duration (_basic.stc.static_) at program
termination (_basic.start.term_), (2) [...]. A program is
ill-formed if the destructor for an object is implicitly used and
it is not accessible (_class.access_).
But it doesn't say what context is used to determine the
accessibility of the destructor that would be invoked at program
termination. I would expect that the construction context would be
used. (Microsoft agrees. Gcc disagrees.)
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]