Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-11-05 23:51:31


MSVC's strange ABI effect seems to let you
identify whether a *polymorphic* type has a virtual d'tor.

I was quite suprised to discover that
when the polymorphic base type doesn' have virtual d'tor,
then the following is true:
sizeof(derived<base>) != sizeof(derived_vdtor<base>).

If the base type has virtual d'tor, then
sizeof(derived<base_vdtor>) == sizeof(derived_vdtor<base_vdtor>).

See the code below. The trick is in using virtual base type.

I could not find any info about it.
Does someone know what is going on?
I checked MSVC v6 and v7.1 ...
they both give consistent results.

#include <iostream>

struct base_vdtor
{
        char c[10];
        virtual ~base_vdtor();
        virtual int f();
};

struct base
{
        char c[10];
        ~base();
        virtual int f();
};

template< typename T >
struct derived_vdtor : virtual T
{
        virtual ~derived_vdtor() {}
};

template< typename T >
struct derived : virtual T
{
        ~derived() {}
};

int main()
{
        std::cout << "virtual dtor\n" <<
                sizeof(derived<base_vdtor>) << " " << sizeof(derived_vdtor<base_vdtor>) << "\n";
        
        std::cout << "plain dtor\n" <<
                sizeof(derived<base>) << " " << sizeof(derived_vdtor<base>) << "\n";
        
        return 0;
}

Eugene

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk