Mail Archives: djgpp/1998/09/22/17:45:27
On Tue, 22 Sep 1998 18:32:51 +0200, DougEleveld <deleveld AT dds DOT nl>
wrote:
>> >Bug:
>> >The static singleton is within the scope of class and should be able to be
>> >destructed, but DJGPP is trying to destroy it at global scope.
>> >*/
>>
>> The scope of the declaration has nothing to do with scope of
>> "destruction". The scope of "contruction" of singelton::instance is
>> the scope of the class by definition. The scope of destruction is the
>> scope of the definition - i.e. global scope. The d'tor is not
>> accessible at global scope.
>So you are saying that a static instance of a class does not have access
>to it's own private constructors/destructors?
Of course _it_ has not. Only member functions of the class have access
to private member functions of the class.
Only a (possibly static) member function of singelton could legally
destroy it by calling
instance.singelton::~singelton();
Destruction is done _via_ a member function ~singelton(), but the
problem is: who has the right to evoke this private member function
singelton::~singelton ? It doesn't evoke "itself".
Formally the static 'instance' defined at file level is destroyed by
the run time system by a call
singelton::instance.~singelton();
alias
singelton::instance.singelton::~singelton();
at the end of the program.
As this formal call is not performed _by_ a member function of
singelton, singelton::~singleton() is not accessible at this point.
The "executor" of this formal call is formally treated as inline code
at file level with normal acess restrictions and therefore the
definition of 'instance' is flagged as an error by _every_ c++
compiler I know of if a non-public dtor is defined.
This example
struct X { protected : /* or private */ ~X() {} };
void f()
{
X x;
}
would yield a syntax error, too, because the run time system has no
access to the d'tor if it would have to destroy x when it goes out of
scope. I think this is exactly the same case.
Regards
Horst
- Raw text -