Topic: An Extra Virtual Destructor Question t


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1996/02/29
Raw View
In article 43e@news.xs4all.nl, veldhuis@xs4all.nl (Wim Veldhuis) writes:
>In message <47voa1$969@gabi.gabi-soft.fr> - kanze@gabi-soft.fr (J. Kanze)
>writes:
>:>
>:>john (j.d.) hickin (hickin@bnr.ca) wrote:
>:>
>:>|>  class X { public: X(); virtual ~X() = 0; };
>:>
>:>|> Has this been considered?
>:>
>:>In what way?  This has always been legal, and I see nothing in the
>:>present draft to change it.  I occasionally use the idiom to force a
>:>class to be abstract even when I want to provide default behavior for
>:>all of the member functions.

>... What you are saying here is that there is somewhere in the draft
>a rule which states that if a dtor is declared pure virtual, a default
>implementation (or none at all) is automatically created. Is this the case ?

No, and I don't think he was implying that it was the case.

You are always allowed to provide an implementation of a pure virtual
function. That function will never be called via the virtual function
call mechanism, however. If you do call a pure virtual function
explicitly, it must be implemented.

The compiler will generate calls to the pure virtual destructor if
any derived type is destroyed (you can't create objects of type X).
If you declare a member function, the compiler does not generate it
for you. Thus, if you declare a pure virtual destructor, you usually
must implement it as well.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ To submit articles: try just posting with your news-reader.
                      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu.
]





Author: b91926@fsgi01.fnal.gov (David Sachs)
Date: 1996/03/01
Raw View
clamage@Eng.Sun.COM (Steve Clamage) writes:

>The compiler will generate calls to the pure virtual destructor if
>any derived type is destroyed (you can't create objects of type X).
>If you declare a member function, the compiler does not generate it
>for you. Thus, if you declare a pure virtual destructor, you usually
>must implement it as well.

Do you think it would be a good idea if the standard allowed
something like:

class X { virtual ~X()=0 {} } // Combined pure virtual + definition
--
***** Listen Americans, the IRS is your taxer,  the IRS is one. *****
David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510
Voice: 1 708 840 3942      Deparment Fax: 1 708 840 3785
---
[ To submit articles: try just posting with your news-reader.
                      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu.
]