Topic: Void pointer problem


Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Mon, 1 Nov 1993 05:31:49 GMT
Raw View
In article <CF4JC8.I1t@ithaca.com> garry@ithaca.com (Garry Wiegand) writes:
>In a recent article rfg@netcom.com (Ronald F. Guilmette) wrote:
>>In general, if the static type of the pointer expression you give to the
>>`delete' operator is not exactly the same as the original static type
>>which was yielded by the original `new' expression which gave you the
>>pointer value in the first place, then you are likely to be in deep
>>doo doo.
>
>If you always had to 'delete' the identical type as you had 'new'd
>then there would never be a need for virtual destructors!!

Please note that I used the phrases "in general" and "LIKELY to be in deep
doo doo".

I know that there are few exceptions, but I properly stated the general rule.
(In C++ *every* general rule has no fewer than five special case exceptions.
(1/2 :-)

--

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




Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Mon, 1 Nov 1993 09:28:21 GMT
Raw View
In article <CF90z2.6EM@ucc.su.OZ.AU> maxtal@physics.su.OZ.AU (John Max Skaller) writes:
>In article <2a51okINNjjp@emx.cc.utexas.edu> jamshid@emx.cc.utexas.edu (Jamshid Afshar) writes:
>>In article <CF5MB7.M6v@ucc.su.oz.au>,
>>John Max Skaller <maxtal@physics.su.OZ.AU> wrote:
>>
>>Hold your horses, C++ actually gets this right.  I think the ARM is
>>explicit enough about this to even satisfy Ron ;-).  See the end of
>>ARM 12.5.  A virtual destructor does all the things John mentions
>>*and* it calls the correct `operator delete()' function.
>
> My apologies to the ARM. The example on p284 is quite
>explict. What happens to access control? Is there any
>at all for 'operator delete'?
>
> What happens if 'delete' is ambiguous???????

Yes.  What indeed!

For example, is there any good reason why the following code should be
rejected by numerous existing compilers?

 struct B1
 {
     void operator delete (void*) { printf ("Yikes!\n"); }
     ~B1 () { }
 };

 struct B2
 {
     void operator delete (void*) { printf ("Yikes!\n"); }
     ~B2 () { }
 };

 struct D : public B1, public B2 { ~D () { } };

Please note that I'm not allocating or deallocating ANYTHING on the heap
here.

--

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