Disable local class variable

class B
{
public:
    virtual ~B(){}
};

class D : public B
{
public:
    D(){}
protected:
    virtual ~D(){}
};

int main()
{
    D d;                // Illegal.

    B *pD = new D;      // Ok.
    delete pD;
    pD = NULL;

    return 0;
}

  As you see, the key is to disable create local variable by prtected access in class D, and call the dtor through polymorphism.

posted @ 2012-09-13 19:54  walfud  阅读(143)  评论(0编辑  收藏  举报