Virtual inheritance can be used to merge multiply occurring base
classes. However, situations may be encountered where multiple occurrences of
base classes em(is) appropriate. Consider the definition of a tt(Truck) (cf.
section ref(Truck)):
        verb(    class Truck: public Car
    {
        int d_trailer_mass;

        public:
            Truck();
            Truck(int engine_mass, int sp, char const *nm,
                   int trailer_mass);

            void setMass(int engine_mass, int trailer_mass);
            int mass() const;
    };
    Truck::Truck(int engine_mass, int sp, char const *nm,
                  int trailer_mass)
    :
        Car(engine_mass, sp, nm)
    {
        d_trailer_mass = trailer_mass;
    }
    int Truck::mass() const
    {
        return                  // sum of:
            Car::mass() +    //   engine part plus
            trailer_mass;         //   the trailer
    })

This definition shows how a tt(Truck) object is constructed to contain two
mass fields: one via its derivation from tt(Car) and one via its own tt(int
d_trailer_mass) data member. Such a definition is of course valid, but it
could also be rewritten. We could derive a tt(Truck) from a tt(Car)
em(and) from a tt(Vehicle), thereby explicitly requesting the double presence
of a tt(Vehicle); one for the mass of the engine and cabin, and one for the
mass of the trailer. A slight complication is that a class organization like
        verb(    class Truck: public Car, public Vehicle)

is not accepted by the bf(C++) compiler. As a tt(Vehicle) is already part
of a tt(Car), it is therefore not needed once again. This organization may,
however, be accepted using a small trick. By creating an additional class
inheriting from tt(Vehicle) and deriving tt(Truck) from that additional class
rather than directly from tt(Vehicle) the problem is solved. Simply derive a
class tt(TrailerVeh) from tt(Vehicle), and then tt(Truck) from tt(Car) and
tt(TrailerVeh):
        verb(    class TrailerVeh: public Vehicle
    {
        public:
            TrailerVeh(int mass)
            :
                Vehicle(mass)
            {}
    };
    class Truck: public Car, public TrailerVeh
    {
        public:
            Truck();
            Truck(int engine_mass, int sp, char const *nm, int trailer_mass);
            void setMass(int engine_mass, int trailer_mass);
            int mass() const;
    };
    inline Truck::Truck(int engine_mass, int sp, char const *nm,
                        int trailer_mass)
    :
        Car(engine_mass, sp, nm),
        TrailerVeh(trailer_mass)
    {}
    inline int Truck::mass() const
    {
        return                      // sum of:
            Car::mass() +        //   engine part plus
            TrailerVeh::mass();   //   the trailer
    })

