1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
Now that it is possible to determine type convertibility, it's easy to
determine whether a type tt(Base) is a (public) base class of a type
tt(Derived).
Inheritance is determined by inspecting convertibility of (const)
pointers. tt(Derived const *) can be converted to tt(Base const *) if
itemization(
it() both types are identical;
it() tt(Base) is a public and unambiguous base class of tt(Derived);
it() and (usually not intended) if tt(Base) is void.
)
Assuming the last conversion isn't used inheritance can be determined
using the following trait class tt(LBaseRDerived). tt(LBaseRDerived) provides
an enum tt(yes) which is 1 if the left type is a base class of the right type
and both types are different:
verbinclude(//LBASERDERIVED examples/conversion.h)
If code should not consider a class to be its own base class, then the
trait class tt(LBaseRtrulyDerived) can be used to perform a strict test. This
trait class adds a test for type-equality:
verbinclude(//LBASERTRUE examples/conversion.h)
Example: the next statement displays tt(1: 0, 2: 1, 3: 0, 4: 1, 5: 0)
when executed from a tt(main) function:
verbinclude(//INHERITANCE examples/conversion.cc)
|