Topic: private destructor?


Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Sat, 18 Sep 1993 00:23:01 GMT
Raw View
In article <CDGqq7.4ns@cbnewse.cb.att.com> grumpy@cbnewse.cb.att.com (Paul J Lucas) writes:
>From article <2787hh$6st@cs.pdx.edu>, by idr@cs.pdx.edu (Ian D Romanick):
>> Ok, here's a skeleton of my classes:
>>
>> class base
>> {
>> public:
>>  base() { ... }
>>  virtual ~base() { ... }
>> };
>>
>> class child : protected base
>> {
>> public:
>>  child() { ... }
>>  virtual ~child() { ... }
>> };
>>
>> In my code, I do a:
>>
>>  array = new child[ number ];
>>  ...
>>  delete [] array;
>>
>> At this point gcc (2.4.5 on an i386-at-sysv3) says:
>>
>> main.cc:70: destructor for type 'base' is private in this scope
>>
>> My question is, why?  I want my base to be protected to prevent the user from
>> doing things that seem logical, but will break the child class, but I need to
>> be able to delete allocated space! (fancy that!)  In my real code, my base is
>> a template, is it possible that could cause the trouble?  This seems very odd
>> to me.  Thanks to all who respond.
>
> gcc is wrong.
>--
> - Paul J. Lucas
>   AT&T Bell Laboratories
>   Naperville, IL

As it happens, I agree completely with Paul Lucas in this instance, however
the rationale behind Paul's opinion (and mine) with respect to this question
are, to say the least, less than immediately obvious... even if one reads
the somewhat more adequate explanation of protected inheritance given in
the most recent X3J16 working paper (rather that reading the inadequate
description of protected inheritance given in the ARM).

If anyone feels that they can provide an adequate explanation (to the original
poster) of why the code should above is actually valid code, please proceed.
I feel quite sure that just watching all of the contortions necessary to
explain this point will be quite amusing.

Follow-ups to comp.std.c++ please.

--

-- Ronald F. Guilmette ------------------------------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------




Author: grumpy@cbnewse.cb.att.com (Paul J Lucas)
Date: Sun, 19 Sep 1993 14:49:10 GMT
Raw View