//  (C) Porkolab 2003   
//
//  A.4.8.
//   
//  Virtual "constructor" and destructor



    //
    // destructors most cases should be virtual:
    //

    class Base
    {
    public:
        virtual ~Base() { ... }
    };

    class Der : public Base
    {
    public:
        virtual ~Der()  { ... }
    };


    Base *bp = new Der;
    // ...
    delete bp;



    //
    // there is no virtual constructor
    // but we can simulate it:
    //
    class Base
    {
    public:
        virtual Base* clone() { return new Base(*this); }
    };

    class Der : public Base
    {
    public:
        virtual Der* clone() { return new Der(*this); }
    };

    for ( Base *bp = first; bp; bp = bp->next() )
    {
        append( bp->clone() );
    }