Code giving SEG FAULT only when the class is being derived!
<p>
I am unable to find out the bug in the below code which i had written[Not for any purpose though].
</p>

<p>
<pre>
<code>
#include &lt iostream &gt
#include &lt cstdlib &gt

using namespace std;


class Base{
public:
        Base(){cout &lt&lt "Base class constructor" &lt&lt endl;}
        void funv() {};
        ~Base(){cout &lt&lt "Base class destructor" &lt&lt endl;} ;
};

class Derived:public Base{
public:
        char *ch;
        Derived():ch(new char[6]()){}
        ~Derived(){
                cout &lt&lt "before" &lt&lt endl;
                delete [] ch;
                ch = NULL;
                cout &lt&lt "after" &lt&lt endl;
        }
};

int main(){

        Derived * ptr = new Derived;

        //memcpy(ptr -> ch,"ar\0",4); // Works when class Derived is derved from base and also when not derived from base

        ptr -> ch = const_cast &lt char* &gt("ar0");  // Works only when class Derived is not derived from class Base

        cout &lt&lt ptr -> ch[1] &lt&lt endl;

        ptr -> funv();

        delete ptr;

        return 0;
}

</code>
</pre>
</p>

<p>
I have commented on the suspected lines of the code.
<p>
I am using sun Studio 12.
</p>
</p>
