RE: Pure virtual destructors in abstract classes

From: Stefano Bettelli (bettelli@tn.infn.it)
Date: Fri Nov 19 1999 - 21:32:14 MET


On 19-Nov-99 Nick West wrote:
> Dear roottalk,
> I am getting rather confused trying to use multiple inheritance with an abstract
> base class. ....... other member functions can remain pure virtual, but
> the destructor appears to be special.
        Indeed it is: the "virtual" specifier has a different meaning 
        for the destructor method. AFAIK the following is true:
        --> if the base class destructor is virtual (not pure virtual),
            then the derived class destructor is virtual too, despite
            it is not declared as such;
        --> the keyword virtual normally means "Call the function in 
            the derived class instead of the one in the base class",
            but for a virtual destructor it means "Call the destructor 
            for the derived class and then the destructor for the base 
            class"
        --> the second commandment for the C++ programmer, according to
            "Practical C++ programming" is: "Thou shalt declare and 
            define thy destructor as virtual such that others may 
            become heir to the fruits of your labors"

> The second reason is to ask for suggestions as to how people who are just 
> starting out should proceed.  When a program halts complaining about 
> unresolved symbol __dt__1AXv what should they do?  In my case I figured it was
> something about CINT, but have no idea about __dt__ or the significance of the
> Xv.  Is there somewhere that explains these symbols?  Are they platform
> specific? - I am running on an Alpha/OSF Digital UNIX V4.0F C++ 6.1.
        These strange function names come from the C++ compiler including
        the argument types in the name itself; moreover constructors,
        destructors and operators might have special strings. You can 
        inspect the symbols (including external ones) in the symbol table 
        of an object with the "nm" UNIX utility (it can also "demangle" 
        the name with the -C option, that is translate it back into human
        readable form). Take a look at the following output (associator is
        one of my classes, "U" stands for "undefined", that is a call to a
        function which is compiled in some other object file and must be 
        linked in later):
                tcsh> nm -C Objects/detector.o | grep associator
                 U associator::~associator(void)
                 U associator::associator(void)
                 U operator<<(ostream &, associator const &)
                 U associator::clear_data_area(void)
                 U associator::do_association(Mc_properties *)
                tcsh> nm Objects/detector.o | grep associator
                 U _._10associator
                 U __10associator
                 U __ls__FR7ostreamRC10associator
                 U clear_data_area__10associator
                 U do_association__10associatorP13Mc_properties
        so if the linker complains about not finding "_._10associator"
        you know you are missing the "associator::~associator(void)"
        destructor; your compiler uses different strings from mine
        e.g. for the destructor ("dt" instead of ".") but I think
        the "nm" utility should work great.

        Regards,
                                        Stefano Bettelli 

----------------------------------------------------------
E-Mail: Stefano Bettelli <bettelli@tn.infn.it>
WWW   : http://meitner.tn.infn.it



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:43 MET