home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!dpg
- From: dpg@extro.ucc.su.OZ.AU (D P Gilbert)
- Subject: Re: Compiler should generate virtual destructors
- Message-ID: <dpg.726062785@extro.ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: Sydney University Computing Service, Sydney, NSW, Australia
- References: <1992Dec31.050150.28929@ucc.su.OZ.AU> <lkc2k7INNajv@exodus.Eng.Sun.COM> <1993Jan3.032228.14386@ucc.su.OZ.AU>
- Date: Sun, 3 Jan 1993 12:06:25 GMT
- Lines: 58
-
- maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
-
- >In article <lkc2k7INNajv@exodus.Eng.Sun.COM> db@argon.Eng.Sun.COM (David Brownell) writes:
- >>maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- >>
- >>> I would like to propose that if a class has virtual functions,
- >>> then any destructor generated by the compiler will be virtual
- >>> by default.
- >>
- >>Hmmm ... given that I've never seen such nonvirtual destructors be
- >>anything except bug, I like the idea of fixing this problem.
- >>
- >>On the other hand, one of the things I'd really like to see changed is
- >>how much stuff a C++ compiler does "for me" automagically. It's a rare
- >>day when it really does what I need to have done; just how often is
- >>memory management broken when pointers "owned" by class instances are
- >>bitwise copied?
-
- > A decent solution could have been had except for the
- >extremely unfortunate (IMHO) decision that 'struct' and 'class'
- >are synonymous (except for public/private defaults).
-
- > For example, how about:
-
- > generate X::X(const X&);
-
- >This could only apply to classes and not 'C' structs for compatibility
- >reasons.
-
- >>
- >>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.
- >>
- >> (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.
-
- > Not possible for C-Structs, compiler MUST automagiocally
- >generate constructors and assignment for these.
-
- >
- > Want to modify (2a) to include 'with virtual functions'?
- > ......
-
- How about a new keyword "__pure" to
- 1) prefix "class" in a class definition to stop automagic
- constructor + assignment generation ++
- 2) prefix "virtual" in a pure virtual function
- declaration to get rid of the "=0" hack
- 3) waste some of the compiler implementor's name space
- (rather the the compiler user's name space). The
- user can #define pure __pure if it causes no problem
-
-
- Doug Gilbert
-