Article View: comp.std.c++
Article #1353Re: Compiler should generate virtual destructors
From: Paul Lucas
Date: Fri, 22 Jan 1993 12:13
Date: Fri, 22 Jan 1993 12:13
55 lines
2510 bytes
2510 bytes
In <harvey.727664973@regina> harvey@opl.com (Harvey Reed) writes:
>db@argon.Eng.Sun.COM (David Brownell) writes:
>>...
>>So, a pair of proposals that I'd be happier to see accepted:
>> (1) It is an error for a class to have virtual functions and a
>> nonvirtual destructor.
A warning, perhaps.
>> (2a) C++ compilers don't automagically generate ANYTHING for classes
>> any more: constructors, destructors, assignment and address-of
>> operators, etc. If such routines are used but not declared and
>> defined, that is an error.
Would break a large part of th the world (like all struct declarations
for starters; see below).
>I think I would feel a lot better about my C++ compiler if I didn't
>have to make a copy-ctor private/unimplemented (as a safegaurd) just
>because I was afraid that I *might* be accidentally copying an object.
>It would be much better if the compiler simply said it was an error
>to copy without a copy-ctor (or whatever), then the programmer can:
>1) remove the need to copy
>2) install the proper method to do the copy
>This goes for all the other automagic stuff too! I cringe when I
>think about automagically adding virtual destructors, even though
>they are most times needed...
Another case for protecting programmers from themselves. For:
struct Point {
int x, y;
};
I don't want to have to write a ctor and assign-op. especially
when the generated ones would work perfectly.
Whenerver one writes a class, one *has* to ask onesself: Do I
need a ctor? An assign-op? One should have to ask onesself
this regardless of whether the compiler did the default ones
for one or not. If one doesn't, then one is just careless.
The default stuff is for convenience. In my experience, and I
would venture others', it's rare to have to forbid copy/assign
anyway. Unless you have a good reason to forbid them, who cares?
Let users copy them.
--
- Paul J. Lucas
AT&T Bell Laboratories
Naperville, IL
Technical Details
Message-ID:
<C198n6.JpD@cs.uiuc.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!sdd.hp.com!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjlReferences:
<1992Dec31.050150.28929@ucc.su.OZ.AU> <lkc2k7INNajv@exodus.Eng.Sun.COM> <harvey.727664973@regina>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sdd.hp.com!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjl From: pjl@cs.uiuc.edu (Paul Lucas) Subject: Re: Compiler should generate virtual destructors Message-ID: <C198n6.JpD@cs.uiuc.edu> Sender: news@cs.uiuc.edu Organization: University of Illinois at Urbana-Champaign References: <1992Dec31.050150.28929@ucc.su.OZ.AU> <lkc2k7INNajv@exodus.Eng.Sun.COM> <harvey.727664973@regina> Date: Fri, 22 Jan 1993 12:13:53 GMT Lines: 55