Re: inhibit compiler warning C4624 for a class hierarchy



"Heinz Ozwirk" wrote:
You can make destructor protected, so it will be
availabale for derived classes while unavailable for
outside users of a class.

Additionally the destructors of all derived classes should
then be protected, too. If one of the derived classes had
a public destructor, instances of that class could be
created on the "stack" without error or even a warning.


Unavailable destructor issue has been discussed recently in
this group. Such code passes compilation only because of MS
extension being applied. Actually, it should be an error,
not a warning. Also, I believe that warning of level 1
shouldn't be treated as anything else than error.

Making an object to be uncreatable on stack is quite
uncommon requirement. So, protected destructor throughout an
hierarchy is acceptable price for it.

Alex


.



Relevant Pages

  • Re: replicated base classes
    ... destructor in a base class if there's derived classes. ... then the derived classes does not warrant virtuals. ... > class A constructor ...
    (alt.comp.lang.learn.c-cpp)
  • Re: base class virtual destructor not resolving inherited virtual functions
    ... an object of "CChild", work with it, and then delete it. ... destructor, which does nothing, and then calls the CBase ... calls a virtual function which is overridden in CChild -- BUT, ... versions overridden by derived classes, ...
    (microsoft.public.vc.mfc)
  • Re: Polymorphism
    ... >>So I am thinking that if the Base class destructor is not made virtual ... >>then when delete is called it won't call the derived classes ... A long time ago I posted an example of an inheritance hierarchy ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Always avoid "new"
    ... Of course if I need a variable number of objects, then I use new and store ... object and make that objects destructor ensure cleanup. ... An additional advantage of allocating on the stack instead of the heap, ...
    (comp.lang.cpp)
  • Re: stack vs heap destruction problem
    ... The object simply parses a ... when I declare it like this: ... > It causes a SEGFAULT when its destructor is called every time. ... unless you don't have enough stack or you are doing something somewhere ...
    (comp.lang.cpp)