//  (C) Porkolab 2003   
//
//  A.4.9.
//   
//  Objects only in heap or never in heap



//
//  Objects only in heap:
// 

#include <new>

class X
{
public:
    X() {}
    void destroy() const { delete this; }
protected:
    ~X() {}
};

class Y : public X { };
//  class Z { X xx; };  // use pointer!


// X x1;
int main()
{
//  X x2;
//  Y y1;
    X* xp = new X;
    Y* yp = new Y;

//  delete xp;
    xp->destroy();
    delete yp;
};



//
//  Objects never on heap:
//


#include <new>

class X
{
private:
    static void *operator new( size_t);
    static void operator delete(void *);
};

class Y : public X { };

X x1;
int main()
{
    X x2;
    Y y1;
//  X* xp = new X;
//  Y* yp = new Y;

//  delete xp;
//  delete yp;
};